The Concept of link list and Double link list is clearly explained in Wikipedia and here.I just want to show you the correct code for making doubly link list because sometimes algorithm is explained great but code is not given their. We first have to make struct and define the structure we want.I just have inserted a character in a node and its next and previous nodes. So our insert method which would insert a node will be like this. And the delete method would be like this. And another method would be which would show All the nodes. Here is the link from where you can download the CPP file of this code.Downloadvoid Insert(char a)
{
if(first == NULL)
{ first = new Node();
first->nxt = NULL;
first->prv = NULL;
first->a = a;
last = first;
}
else
{ last->nxt = new Node();
last->nxt->a = a;
last->nxt->prv = last;
last = last->nxt;
last->prv->nxt = last;
}
last->nxt = NULL;
}void Delete(char b)
{
Node * temp = first;
int i = 1;
while(temp!= NULL)
{ if(temp->a == b)
{ temp->prv->nxt = temp->nxt;
temp->nxt->prv = temp->prv;
break;
}
temp = temp->nxt;
}
}void ShowAll()
{
Node * temp = first;
int i = 1;
while(temp!= NULL)
{
printf("\nAt poistion %d we have %c ",i,temp->a);
temp = temp->nxt;
}
cout << "\nEnd Of List"<< endl;
}
Double Link List Code
Posted by cricjoy Friday, May 1, 2009 at 6:22 AM
Subscribe to:
Post Comments (Atom)
0 comments
Post a Comment