![]() |
| | #1 |
| Registered User Join Date: Mar 2008
Posts: 71
| Pointers to pointers in linked lists I'm a beginner in C++ trying to write himself a class for a new datatype that wouldn't be as "inflexible" as the default ones concerning storage capacity. I'm using linked lists to store the value of the number, and I wrote this piece of code to add a node to the end of the list, but I have absolutely no idea if it'll work. In fact, knowing how my experiments usually end, I have a hunch it won't But just to be sure, could anyone go over the code and tell me if it'll work or not?Code: void large::createNode(storage_list** param) {
storage_list *temp; //Create a temporary pointer
temp = new storage_list; //Allocate memory
temp->next_node = NULL; //Set pointer to next node
temp->previous_node = *param; //Set pointer to previous node
*param->next_node = temp; //Assign "value"
lastNode = temp; //Set pointer defined in class large
}
large is the class, and storage_list is the linked list (actually it's a double-linked list, isn't it...?) Thanks in advance ;-) |
| G4B3 is offline | |
| | #2 |
| Frequently Quite Prolix Join Date: Apr 2005 Location: Canada
Posts: 7,629
| Just one thing: instead of this Code: *param->next_node = temp; //Assign "value" Code: (*param)->next_node = temp; //Assign "value" Code: *(param->next_node) = temp; //Assign "value"
__________________ dwk Seek and ye shall find. quaere et invenies. "Simplicity does not precede complexity, but follows it." -- Alan Perlis "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra "The only real mistake is the one from which we learn nothing." -- John Powell Other boards: DaniWeb, TPS Unofficial Wiki FAQ: cpwiki.sf.net My website: http://dwks.theprogrammingsite.com/ Projects: codeform, xuni, atlantis, etc. New project: nort |
| dwks is offline | |
| | #3 |
| Registered User Join Date: Mar 2008
Posts: 71
| yes, you're right, I didn't realize that :-) Thx for the help |
| G4B3 is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Doubly linked lists | mohanlon | C Programming | 7 | 06-27-2009 07:45 PM |
| Linked Lists 101 | The Brain | C++ Programming | 5 | 07-24-2004 04:32 PM |
| Request for comments | Prelude | A Brief History of Cprogramming.com | 15 | 01-02-2004 10:33 AM |
| eof in fstream & singly linked lists | mazo | C++ Programming | 3 | 06-03-2002 09:50 AM |
| Linked lists and file i/o, and some other stuff | ninja | C++ Programming | 9 | 05-19-2002 07:15 PM |