944,183 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 27692
  • C++ RSS
Jan 13th, 2006
0

The C++ LINKED LIST

Expand Post »
hey guys, im a new guy here in the forum and im also an IT student who gets into C++ troubles most of the time, but enough about that... i just wanna ask if anyone can help me in my linked list problem, i think its about pointers and address. like a->link, well thats what it looked like. Problem is i dont understand a thing and my prof wont even give me an example, i dont even get the slightest idea of what's it all about and i dont know where to start, SO CAN ANYONE PLS SHOW ME AN EXAMPLE,even just the basic ones THANKS!!!
^_^
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Twins_effect is offline Offline
3 posts
since Jan 2006
Jan 13th, 2006
0

Re: The C++ LINKED LIST

try google + "linked lists"
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Jan 14th, 2006
0

Re: The C++ LINKED LIST

Linked list are typically used to work with data structures.
Access to items in the list is controlled by pointers.

This is a very simple example to construct a linked list. You will need to do a lot more reading to use them correctly.

One thing to remember:
You must delete all the list items when exiting the program otherwise you will create a memory leak.
C++ Syntax (Toggle Plain Text)
  1. struct dataRec {
  2. type data;
  3. dataRec *next;
  4. }
  5.  
  6. dataRec *prList = NULL; // the list anchor
  7.  
  8. function addRecord(dataRec *prList) {
  9. dataRec *temp = new dataRec; // create a new record to add to list
  10. temp->data = whatever;
  11. temp->next = NULL;
  12.  
  13. // Now add this record to the end of the list
  14. dataRec *curr = prList;
  15. if (curr == NULL) { // the list is empty
  16. prList = temp; // prList, the anchor, now points to the first record
  17. }
  18. else {
  19. if (curr->next == NULL) { // last record in list
  20. curr->next = temp; // add temp to end of list
  21. }
  22. else { // move up the list until the last entry
  23. curr = curr->next;
  24. }
  25. }
  26. }
Reputation Points: 11
Solved Threads: 0
Light Poster
Nedals is offline Offline
43 posts
since Dec 2005
Jan 15th, 2006
0

Re: The C++ LINKED LIST

thanks, i really appreciate it! i think i'll do some head crackinh for awhile to master this ^^
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Twins_effect is offline Offline
3 posts
since Jan 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Using C++ OOP class.....
Next Thread in C++ Forum Timeline: Creating data packets?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC