|
-
December 5th, 2011, 04:07 PM
#5
Re: Linked List Problem
 Originally Posted by josh26757
The struct used for the Linked List -->
Code:
struct Event{
string event, date, location, time, note;
Event *next;
Event *last;
};
Here is an example of what I'm referring to:
Code:
#include <list>
#include <string>
struct Event
{
std::string event, date, location, time, note;
Event(const std::string& event_,
const std::string& date_,
const std::string& location_,
const std::string& time_,
const std::string& note_) :
event(event_), date(date_), location(location_),
time(time_), note(note_) { }
};
typedef std::list<Event> EventList;
int main()
{
EventList evList;
// add 3 events to the eventList linked list
evList.push_back(Event("Event1", "","","",""));
evList.push_back(Event("Event2", "","","",""));
evList.push_back(Event("Event2", "","","",""));
}
I just added 3 Events to a linked list. I know this works correctly without even compiling or running it. Why? Because it is guaranteed to work due to usage of standard library, and not my home-made linked list which could have bugs.
No memory leaks, no pointers, no calls to new[]/delete[], nothing. You can also remove items from the linked list, sort it, etc.
Regards,
Paul McKenzie
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|