Linked List of struct

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jan 2008
Posts: 77
Reputation: number87 is an unknown quantity at this point 
Solved Threads: 0
number87 number87 is offline Offline
Junior Poster in Training

Linked List of struct

 
0
  #1
Nov 20th, 2008
I am creating a linked list which links a struct of data together. However, this is my problem, if I declare struct Node first then the Event type wont exist, but if I declare struct Event first then nodePtr wont exist....im kinda stuck here as to how I should declare them.

  1. struct Event
  2. {
  3. void addEvent();
  4.  
  5. tm startTime, endTime;
  6. string eventItem;
  7. string eventNotes;
  8. char allDay;
  9. nodePtr head, tail;
  10.  
  11. };
  12.  
  13.  
  14. struct Node
  15. {
  16. Event eventNode;
  17. Node *next;
  18. };
  19.  
  20. typedef Node* nodePtr;
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 32
Reputation: emotionalone is an unknown quantity at this point 
Solved Threads: 4
emotionalone emotionalone is offline Offline
Light Poster

Re: Linked List of struct

 
0
  #2
Nov 20th, 2008
Not sure of what you want to accomplish here. This piece of info might help getting the same results using a different method.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 77
Reputation: number87 is an unknown quantity at this point 
Solved Threads: 0
number87 number87 is offline Offline
Junior Poster in Training

Re: Linked List of struct

 
0
  #3
Nov 20th, 2008
ok what im trying to do have a list of Events (which are actually a struct type containning data such as time date etc). And my problem as can be seen above is that I do not know how to resolve their declarations. I cant declare struct Event first because it contains pointers to the next Event struct. And I cant declare struct Node first because the node is of Event type.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 320
Reputation: cikara21 is an unknown quantity at this point 
Solved Threads: 63
cikara21's Avatar
cikara21 cikara21 is offline Offline
Posting Whiz

Re: Linked List of struct

 
0
  #4
Nov 21st, 2008
  1. struct Event
  2. {
  3. void addEvent();
  4.  
  5. tm startTime, endTime;
  6. string eventItem;
  7. string eventNotes;
  8. char allDay;
  9. nodePtr *head, *tail; //-- a pointer!, maybe...
  10.  
  11. };
  12.  
  13.  
  14. struct Node
  15. {
  16. Event *eventNode; //-- a pointer!, maybe.
  17. Node *next;
  18. };
  19.  
  20. typedef Node* nodePtr;
.:-cikara21-:.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 42
Reputation: littlestone is an unknown quantity at this point 
Solved Threads: 6
littlestone littlestone is offline Offline
Light Poster

Re: Linked List of struct

 
0
  #5
Nov 21st, 2008
Maybe, you confused the functionality of Event struct and Node struct.

There are two ways to reach you objective.
First,
  1. struct EventNode
  2. {
  3. tm startTime, endTime;
  4. string eventItem;
  5. string eventNotes;
  6. char allDay;
  7.  
  8. EventNode* next;
  9. };
  10.  
  11. struct EventList
  12. {
  13. void addEvent();
  14. ... // other member functions used to sustain the list
  15. private:
  16. EventNode* head;
  17. EventNode* tail;
  18. };

another way use the list of STL to store the event.

  1. struct Event
  2. {
  3. tm startTime, endTime;
  4. string eventItem;
  5. string eventNotes;
  6. char allDay;
  7. };
  8.  
  9. std::list<Event> eventList;
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 77
Reputation: number87 is an unknown quantity at this point 
Solved Threads: 0
number87 number87 is offline Offline
Junior Poster in Training

Re: Linked List of struct

 
0
  #6
Nov 21st, 2008
ah ok i get what u mean
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC