QNode
class
defined earlier (oll1.cpp),
reuse relevant portions of the code to provide a generic
queue node class which can act as the queue head or as
a list node.
The idea here is to use the QNode
in such
a way so that while the node itself is attached to a list,
via its forward and back pointers, it also uses a
``user pointer'' to point to an arbitrary object. That is,
the QNode
's user pointer is pointing to
void
, or simply a void pointer.
The user pointer must be initialized to point to the object passed to the node constructor as an argument.
Provide the following member functions for the
QNode
class:
fadd()
eadd()
fdel()
edel()
fnext()
lprev()
uptr()
QHead
class. Note the new
uptr()
member function. This member
function returns the user void pointer. Note also that the
forward and backward print routines are no longer part of the
QNode
class. They've been removed due to
the fact that a QNode
object has no way
of ``knowing'' what is being stored in the user data
and thus it cannot not be expected to print or even
access this data. This functionality has been relegated
to whatever user class is using the QNode
class for linked list storage.
Your code should be arranged so that the QNode
class interface is in separate header (.h
) file,
while the class interface is in a .c
file.
Stack
class which will use the
QNode
class to store its objects on the
queue's doubly linked list. The Stack
class
uses the QNode
class for this purpose via object
composition. That is, it simply has a
QNode*
(pointer to QNode
) private
data member. Include also an integer private data member to
store the stack integer values.
Provide the following stack operations:
data()
push()
top()
pop()
fprint()
Hints:
QNode*
private data member is, by extension, used as the queue
head node.
QNode*
private data member, especially being
aware when the queue node pointer is being
used as the queue head (in the stack
implementation you can assume that
this
pointer points to the stack
head),
uptr()
user data access
routine (here, since uptr()
returns
a pointer to void, you'll need to cast the void
pointer to a stack node pointer).
Your code should be arranged so that the Stack
class interface is in separate header (.h
) file,
while the class interface is in a .c
file.
Stack
class by
creating a user-specified sized stack of integers.
This is similar to the doubly linked list program, except that
now you're using the Stack
class to indirectly
create a doubly linked list.
Your code should be arranged so that the main()
routine is in a separate .c
file. Use a Makefile
to compile all the modules.
Here's the sample output:
stack should be empty: stack is empty
Enter stack size: 5
printing forwards:
4
3
2
1
0
getting top node:
4
removing from front:
4
3
2
1
0
stack should be empty: stack is empty
Warning: while the output of this program may seem somewhat
mundane, its conceptualization and proper implementation may
not be. Start early! First understand the specifications of
the problem and then design the proper data structures and
their usage.
The general presentation of your document counts! (This includes qualities such as neatness, formatting, and legibility.)