DDL
DDL
*/
#include<iostream>
#include<cstdio>
#include<cstdlib>
/*
* Node Declaration
*/
struct node
int info;
}*start;
/*
Class Declaration
*/
class double_llist
public:
void display_dlist();
void count();
void reverse();
double_llist()
start = NULL;
};
/*
*/
int main()
double_llist dl;
while (1)
cout<<endl<<"----------------------------"<<endl;
cout<<endl<<"----------------------------"<<endl;
cout<<"1.Create Node"<<endl;
cout<<"2.Add at begining"<<endl;
cout<<"4.Delete"<<endl;
cout<<"5.Display"<<endl;
cout<<"6.Count"<<endl;
cout<<"7.Reverse"<<endl;
cout<<"8.Quit"<<endl;
cin>>choice;
switch ( choice )
case 1:
cin>>element;
dl.create_list(element);
cout<<endl;
break;
case 2:
cin>>element;
dl.add_begin(element);
cout<<endl;
break;
case 3:
cin>>element;
cin>>position;
dl.add_after(element, position);
cout<<endl;
break;
case 4:
if (start == NULL)
break;
cin>>element;
dl.delete_element(element);
cout<<endl;
break;
case 5:
dl.display_dlist();
cout<<endl;
break;
case 6:
dl.count();
break;
case 7:
if (start == NULL)
break;
dl.reverse();
cout<<endl;
break;
case 8:
exit(1);
default:
cout<<"Wrong choice"<<endl;
return 0;
/*
* Create Double Link List
*/
temp->info = value;
temp->next = NULL;
if (start == NULL)
temp->prev = NULL;
start = temp;
else
s = start;
s = s->next;
s->next = temp;
temp->prev = s;
/*
*/
if (start == NULL)
{
cout<<"First Create the list."<<endl;
return;
temp->prev = NULL;
temp->info = value;
temp->next = start;
start->prev = temp;
start = temp;
cout<<"Element Inserted"<<endl;
/*
*/
if (start == NULL)
return;
int i;
q = start;
q = q->next;
if (q == NULL)
cout<<pos<<" elements."<<endl;
return;
tmp->info = value;
if (q->next == NULL)
q->next = tmp;
tmp->next = NULL;
tmp->prev = q;
else
tmp->next = q->next;
tmp->next->prev = tmp;
q->next = tmp;
tmp->prev = q;
cout<<"Element Inserted"<<endl;
/*
*/
{
struct node *tmp, *q;
if (start->info == value)
tmp = start;
start = start->next;
start->prev = NULL;
cout<<"Element Deleted"<<endl;
free(tmp);
return;
q = start;
if (q->next->info == value)
tmp = q->next;
q->next = tmp->next;
tmp->next->prev = q;
cout<<"Element Deleted"<<endl;
free(tmp);
return;
q = q->next;
if (q->next->info == value)
{
tmp = q->next;
free(tmp);
q->next = NULL;
cout<<"Element Deleted"<<endl;
return;
/*
*/
void double_llist::display_dlist()
if (start == NULL)
return;
q = start;
while (q != NULL)
q = q->next;
cout<<"NULL"<<endl;
}
/*
*/
void double_llist::count()
int cnt = 0;
while (q != NULL)
q = q->next;
cnt++;
/*
*/
void double_llist::reverse()
p1 = start;
p2 = p1->next;
p1->next = NULL;
p1->prev = p2;
p2->prev = p2->next;
p2->next = p1;
p1 = p2;
p2 = p2->prev;
start = p1;
cout<<"List Reversed"<<endl;