![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 |
|
Programmer
|
one more thing about doubly linked lists. i've written a program that allows you to add new nodes to either beginning or end of the list. if i call the function for adding a node to the beginning of the list, memory can't be read as it says. however, if i add a node to the end of the list first, and THEN to the beginning, everything works just fine.
why is that? |
|
|
|
|
|
#12 |
|
Battle Programmer
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 770
Rep Power: 3
![]() |
Explain what you mean by "memory can't be read as it says." And do you check for an empty list when you add new nodes?
__________________
<insert disclaimer here> <insert shameless plug for Visual Studio here> |
|
|
|
|
|
#13 |
|
Hobbyist Programmer
Join Date: Feb 2006
Posts: 214
Rep Power: 0
![]() |
I was going to create a new thread for this. However, since we're on the topic of linked lists. When would you use a doubly linked list? I'm asking because I can see the point of having a single linked list. For instance, lets say you have a list of integers: You pass the integer to the head node and the head note will pass the integer to the next internal node. In effect, you're able to sort all the integers by doing this. Basically, "if the value is bigger than me let the next node deal with it. However, if the value is less than me then store it's address. " Well, that's a single linked lists. So why on earth would you want a second instance variable that stores the address of the last node?
Can someone please give me an example of when you would need the adress of the node behind the current node (e.g: doubly linked list) ? [/Off Topic]
__________________
Death smiles at us all. All a man can do is smile back. |
|
|
|
|
|
#14 | |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Quote:
The purpose of a doubly-linked list is that you can move back and forth, instead of always having to track from the root. For instance, if you want to insert a node before the current node, you need to have the address of the previous node, so you can rechain. You can write code to keep the previous as you track through the list, but it's less trouble to just have it available.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
|
#15 | |
|
Programming Guru
![]() Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 6
![]() |
how do you eat a reese's?
same thing with trees. Quote:
YOU define the criteria, don't ask me "guess how i put my pants on today"? i don't fucking know. if you said "left leg first, then right", i might be able to help. same shit with trees. insertion, deletion, and traversal operations may have different properties depending on your tree.
__________________
i put on my robe and wizard hat... Have you ever heard of Plato, Aristotle, Socrates?...Morons. |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| linked list problems | bl00dninja | C++ | 6 | Feb 17th, 2008 11:30 AM |
| dev c++ software, template problem | cairo | C++ | 11 | Jun 2nd, 2006 1:42 PM |
| Singly Linked List Help | Firebar | Java | 3 | May 22nd, 2005 11:56 AM |
| User-defined creatNode and deleteNode functions for a doubly-linked list | jgs | C | 2 | Apr 28th, 2005 9:53 AM |
| airport Log program using 3D linked List : problem reading from file | gemini_shooter | C++ | 0 | Mar 2nd, 2005 5:12 PM |