Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

pointers in linked list

 
Castulo Ruiz
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
currently im working on a doubly linked list and Im not sure what the difference are between

&&


don't they both point at node?

 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nope. My advise: draw the datastructure on a piece of paper. Then you'll be able to figure it out.
 
Castulo Ruiz
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The way im seeing it is that (back = node;) means that back will point at the node.
while (back.next=node) means that 'back' will look at what its pointing at, lets say node2 and make the pointer of node2 point to node.
so im not sure if im seeing this correctly.
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does this picture help?
Temp.png
[Thumbnail for Temp.png]
 
Ove Lindström
Ranch Hand
Posts: 326
Android Firefox Browser Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Castulo Ruiz wrote:The way im seeing it is that (back = node;) means that back will point at the node.
while (back.next=node) means that 'back' will look at what its pointing at, lets say node2 and make the pointer of node2 point to node.
so im not sure if im seeing this correctly.


In a double linked list, you should always be able to get the next node and the back node. If back gives you the same node as you already had, then you are at the head of the list. If next gives you the same node, then you are at the end of the list.

Some implementations do use NULL as markers for head and tail.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic