DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C++ (http://www.daniweb.com/forums/forum8.html)
-   -   The C++ LINKED LIST (http://www.daniweb.com/forums/thread38016.html)

Twins_effect Jan 13th, 2006 9:34 am
The C++ LINKED LIST
 
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!!!
^_^

iamthwee Jan 13th, 2006 10:30 am
Re: The C++ LINKED LIST
 
try google + "linked lists"

Nedals Jan 14th, 2006 3:32 am
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.
struct dataRec {
  type    data;
  dataRec  *next;
}

dataRec *prList = NULL;  // the list anchor

function addRecord(dataRec *prList) {
  dataRec *temp = new dataRec;  // create a new record to add to list
  temp->data = whatever;
  temp->next = NULL;

  // Now add this record to the end of the list
  dataRec *curr = prList;       
  if (curr == NULL) {  // the list is empty
    prList = temp;  // prList, the anchor, now points to the first record
  }
  else {
    if (curr->next == NULL) { // last record in list
      curr->next = temp;  // add temp to end of list
    }
    else {  // move up the list until the last entry
      curr = curr->next;
    }
  }
}

Twins_effect Jan 15th, 2006 4:49 am
Re: The C++ LINKED LIST
 
thanks, i really appreciate it! i think i'll do some head crackinh for awhile to master this ^^


All times are GMT -4. The time now is 5:45 am.

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