DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C++ (http://www.daniweb.com/forums/forum8.html)
-   -   Linked List of struct (http://www.daniweb.com/forums/thread158695.html)

number87 Nov 20th, 2008 10:48 pm
Linked List of struct
 
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;

emotionalone Nov 20th, 2008 10:54 pm
Re: Linked List of struct
 
Not sure of what you want to accomplish here. This piece of info might help getting the same results using a different method.

number87 Nov 20th, 2008 11:11 pm
Re: Linked List of struct
 
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.

cikara21 Nov 21st, 2008 4:48 am
Re: Linked List of struct
 
struct Event
{
      void addEvent();
     
      tm startTime, endTime;
      string eventItem;
      string eventNotes;
      char allDay;
      nodePtr *head, *tail; //-- a pointer!, maybe...
                   
};


struct Node
{
      Event *eventNode; //-- a pointer!, maybe.
      Node *next;
};

typedef Node* nodePtr;

littlestone Nov 21st, 2008 5:35 am
Re: Linked List of struct
 
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;

number87 Nov 21st, 2008 6:01 am
Re: Linked List of struct
 
ah ok i get what u mean


All times are GMT -4. The time now is 5:55 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC