When you create the 1st node I see front and back = the new node. When you add the 2nd node front gets modified, along with back, because they both pointed to the same address, but when you add a 3rd node how is front getting the 3rd node because back = n (address of n was passed to back) so how is front getting the 3rd node.
[code]
//An example of a simple double linked list using OOP techniques
#include <iostream>
using namespace std;
struct Node
{
double value;
Node *N,*P;
Node(double y)
{
value = y;
N = P = NULL;
}
};
class doubleLinkedList
{
Node *front;
Node *back;
public:
doubleLinkedList()
{ front = NULL; back = NULL; }
~doubleLinkedList(){ destroyList();}
void appendNodeBack(double x);
void dispNodesForward();
void dispNodesReverse();
void destroyList();
};
}
void doubleLinkedList::appendNodeBack(double x)
{
Node *n = new Node(x);
if( back == NULL)
{
front = n;
back = n;
}
else
{
back->N = n;
n->P = back;
back = n;
}
//append nodes to back of the list
for( int i = 1 ; i < 4 ; i++)
list->appendNodeBack(11.0 - (1.1 * i));
cout << endl << endl;
list->dispNodesForward();
list->dispNodesReverse();
I don't see how front->next get an assignment. So when you print front to back how does temp = temp->next no what the next address is. Is it every time you add a node to back in memory you are adding the same node to front even though front is not being modified in the code. So when you print front to back, front is the head and front->n is the next node.
I think I under stand it. Once back->N gests an address Front->N gets the same address because in the beginning they are at the same address. So that starts the order. So when you go Front->N->N it knows to go to the next spot on memory.