LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Linked Lists and Queues (https://www.linuxquestions.org/questions/programming-9/linked-lists-and-queues-311297/)

Kroenecker 04-08-2005 10:46 PM

Linked Lists and Queues
 
*********If my code below contains an error, you don't need to let me know. I just want
to know if I am on the right track*********

I have to do the following:

Make a linked list class (done for the most part).
Make a que class.

Right now inside the linked list class I have a stuct that contains the data and a pointer to the next node. I also have a pointer to a seperate Que class.

For the list:

struct ListNode
{
ListItemType name;
ListNode * forward;
ListNode * backward;
QueType * que;
};

class linkedList
{
public:
linkedList();
~linkedList();
void addLink(string);
void removeLink(string);
bool searchLink(string);
void compareLink(string);
bool isEmpty();
bool isFull();
void clearList();
private:
ListNode * circle;
};


For the Queue:

struct QueNode
{
ItemType data;
QueNode *link;
};

class Que
{
public:
Que();
Que(const Que &);
const Que &operator=(const Que &);
unsigned long lengthIs(void)const;
~Que();
void MakeEmpty();
bool IsEmpty()const;
bool IsFull()const;
void Enqueue(const ItemType &);
void Dequeue(ItemType &);
void debugPrint(std::ostream &)const;
void removeLast(ItemType &);
void switchFirstLast(void);
private:
QueNode *first;
QueNode *last;
unsigned long length;
};

Now my question is can I access the public member functions of the Que class from within member functions of the Linked List class without using inheritance?

For instance: circle->que->MakeEmpty();

I guess I'm being a bit dumb about this. If this makes any sense, some pointers would be appreciated.

Kroenecker 04-08-2005 10:49 PM

Nevermind:P I made a typo and have it all straightened out :p

Siavash 04-09-2005 01:59 AM

Yes you ca naccess the public member functions of the Que class from within member functions of the Linked List class without using inheritance, but you should let the "LinkedList" know the "Que".


All times are GMT -5. The time now is 09:31 PM.