RSS Forums RSS

Linked List of struct

Please support our C++ advertiser: Programming Forums
Reply
Posts: 66
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

  #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.

struct Event
{
       void addEvent();
       
       tm startTime, endTime;
       string eventItem;
       string eventNotes;
       char allDay;
       nodePtr head, tail;
                     
};


struct Node
{
       Event eventNode;
       Node *next;
};

typedef Node* nodePtr;
AddThis Social Bookmark Button
Reply With Quote  
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

  #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  
Posts: 66
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

  #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  
Posts: 314
Reputation: cikara21 is an unknown quantity at this point 
Solved Threads: 61
cikara21's Avatar
cikara21 cikara21 is offline Offline
Posting Whiz

Re: Linked List of struct

  #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  
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

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

There are two ways to reach you objective.
First,
struct EventNode
{
  tm startTime, endTime;
  string eventItem;
  string eventNotes;
  char allDay;
  
  EventNode* next;
};

struct EventList
{
  void addEvent();
  ... // other member functions used to sustain the list 
private:
  EventNode* head;
  EventNode* tail;
};

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

struct Event
{
  tm startTime, endTime;
  string eventItem;
  string eventNotes;
  char allDay;
};

std::list<Event> eventList;
Reply With Quote  
Posts: 66
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

  #6  
Nov 21st, 2008
ah ok i get what u mean
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Views: 874 | Replies: 5 | Currently Viewing: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 12:59 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC