Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 31st, 2006, 5:30 AM   #11
n00b
Programmer
 
Join Date: Sep 2005
Posts: 69
Rep Power: 4 n00b is on a distinguished road
Send a message via MSN to n00b
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?
n00b is offline   Reply With Quote
Old Oct 31st, 2006, 5:44 AM   #12
Jimbo
Battle Programmer
 
Jimbo's Avatar
 
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 770
Rep Power: 3 Jimbo is on a distinguished road
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>
Jimbo is offline   Reply With Quote
Old Oct 31st, 2006, 11:31 PM   #13
Eric the Red
Hobbyist Programmer
 
Eric the Red's Avatar
 
Join Date: Feb 2006
Posts: 214
Rep Power: 0 Eric the Red is an unknown quantity at this point
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.
Eric the Red is offline   Reply With Quote
Old Oct 31st, 2006, 11:38 PM   #14
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Quote:
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.
This is a nice idea to incorporate into a linked-list class, but it is not a function of a linked list, per se.

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
DaWei is offline   Reply With Quote
Old Nov 4th, 2006, 3:24 AM   #15
bl00dninja
Programming Guru
 
bl00dninja's Avatar
 
Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 6 bl00dninja is on a distinguished road
how do you eat a reese's?

same thing with trees.

Quote:
-...also for adding a new node into the binary tree
what type of binary tree?...binary search tree, max-heap, min-heap...etc.

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.
bl00dninja is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:56 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC