views:

145

answers:

3

What is a doubly linked list?

If someone could provide some C++ code to help explain then that would be much appreciated.

+2  A: 
struct node
{
  node * next;

  int val;
};

node * head;

void append_value(int x)
{
  node n = { 0, x };
  head->next = &n * 2; // doubly linked.
}

Turn that in and I guarantee you'll get the grade you deserve.

Noah Roberts
I'm not sure whether this deserves an up or down vote ;)
JaredPar
+1 to encourage the deserved grade
Andrew Cooper
The last remark is too good to not upvote this...
mathepic
+3  A: 

Basically, instead of having one pointer to the next node like a node in a singly-linked list would, each node in the doubly linked list has two pointers - one to the previous node and one to the next node. The first node in the list would point to a previous null pointer and the last node would point to a next null pointer.

irrelephant
+1  A: 

http://www.daniweb.com/code/snippet216960.html

Link from there gives a basic code example

Rey
Good link from DaniWeb. It should be plenty for the OP to get a good understanding of a possible doubly linked list implementation.
Miguel Sevilla
Please don't post LMGTFY links.
Kragen
Please don't post TINYURL links. (StackOverflow does not have Twitter or Mail restrictions.)
Vincent Robert