#define DELAY 150000000
#include<iostream>
using namespace std;
#include<stdlib.h>
int count;
void swap();
void visual();
void delay();
class dll
{
public:
int data;
class dll *next,*prev;
}*first,*last,*pf,*pl,*qf,*ql,*xf,*temp;
int main()
{
visual();
int c;
char ch='y';
while(ch=='y'|| ch=='Y')
{
system("cls");
cout<<"\nOPERATIONS:\n1:ADD NODE\n2:DISPLAY DOUBLY LIST\n\nYour choice:";
cin>>c;
switch(c)
{
case 1:{
if(first==nullptr)
{
first=new dll;
cout<<"Enter data to node "<<++count<<" : ";
cin>>first->data;
first->prev=nullptr;
first->next=nullptr;
last=first;
}
else
{
temp=new dll;
cout<<"Enter data to node "<<++count<<" : ";
cin>>temp->data;
temp->prev=last;
last->next=temp;
temp->next=nullptr;
last=temp;
temp=nullptr;
}
}
break;
case 2:{
if(count==0)
{
cout<<"\n\a\aEmpty List!!";
break;
}
system("cls");
cout<<"\nList Details before swapping:->>\n\n";
temp=first;
cout<<"\nElement Current Address Next Address Previous Address\n\n";
for(int i=0;i<count;i++,temp=temp->next)
{
cout<<" "<<temp->data<<" "<<temp<<" "<<temp->next<<" "<<temp->prev;
cout<<endl<<endl;
}
cout<<"swapswapswapswapswapswapswapswapswapswapswapswapswapswapswapswapswapswapswapswap";
swap();
cout<<"\n\nList Details after swapping:->>\n\n";
temp=first;
cout<<"\nElement Current Address Next Address Previous Address\n\n";
for(int i=0;i<count;i++,temp=temp->next)
{
cout<<" "<<temp->data<<" "<<temp<<" "<<temp->next<<" "<<temp->prev;
cout<<endl<<endl;
}
}
break;
default:cout<<"\nWrong entry!!";
}
cout<<"\a\nWANT TO CONTINUE?(Y/N):";
cin>>ch;
}
return 0;
}
void swap()
{
pl=first;
ql=last;
pf=pl;
qf=ql;
if(count==2 || count==3)
{
pf->prev=pf->next;
pf->next=nullptr;
qf->next=qf->prev;
qf->prev=nullptr;
first=qf;
last=pf;
return;
}
while((pf->next)!=(qf->prev) && (pf->next)!=qf)
{
pl=pl->next;
ql=ql->prev;
if(pf==first)
{
pl->prev=qf;
qf->next=pl;
qf->prev=nullptr;
first=qf;
ql->next=pf;
pf->prev=ql;
pf->next=nullptr;
last=pf;
}
else
{
pl->prev=qf;
(pf->prev)->next=qf;
ql->next=pf;
(qf->next)->prev=pf;
qf->prev=pf->prev;
pf->next=qf->next;
pf->prev=ql;
qf->next=pl;
}
pf=pl;
qf=ql;
}
if(count%2==0)
{
pf=pl->prev;
qf=ql->next;
pl->next=qf;
pl->prev=ql;
ql->next=pl;
ql->prev=pf;
pf->next=ql;
qf->prev=pl;
}
else
{
xf=pl->next;
pf=pl->prev;
qf=ql->next;
pl->next=qf;
pl->prev=xf;
ql->next=xf;
ql->prev=pf;
pf->next=ql;
qf->prev=pl;
xf->prev=ql;
xf->next=pl;
}
}
void visual()
{
system("cls");
cout<<"LOADING,PLEASE WAIT";
for(int j=0;j<8;j++)
{
cout<<".\a";
delay();
}
}
void delay()
{
for(int i=0;i<DELAY;i++)
continue;
}
#include<iostream>
using namespace std;
#include<stdlib.h>
int count;
void swap();
void visual();
void delay();
class dll
{
public:
int data;
class dll *next,*prev;
}*first,*last,*pf,*pl,*qf,*ql,*xf,*temp;
int main()
{
visual();
int c;
char ch='y';
while(ch=='y'|| ch=='Y')
{
system("cls");
cout<<"\nOPERATIONS:\n1:ADD NODE\n2:DISPLAY DOUBLY LIST\n\nYour choice:";
cin>>c;
switch(c)
{
case 1:{
if(first==nullptr)
{
first=new dll;
cout<<"Enter data to node "<<++count<<" : ";
cin>>first->data;
first->prev=nullptr;
first->next=nullptr;
last=first;
}
else
{
temp=new dll;
cout<<"Enter data to node "<<++count<<" : ";
cin>>temp->data;
temp->prev=last;
last->next=temp;
temp->next=nullptr;
last=temp;
temp=nullptr;
}
}
break;
case 2:{
if(count==0)
{
cout<<"\n\a\aEmpty List!!";
break;
}
system("cls");
cout<<"\nList Details before swapping:->>\n\n";
temp=first;
cout<<"\nElement Current Address Next Address Previous Address\n\n";
for(int i=0;i<count;i++,temp=temp->next)
{
cout<<" "<<temp->data<<" "<<temp<<" "<<temp->next<<" "<<temp->prev;
cout<<endl<<endl;
}
cout<<"swapswapswapswapswapswapswapswapswapswapswapswapswapswapswapswapswapswapswapswap";
swap();
cout<<"\n\nList Details after swapping:->>\n\n";
temp=first;
cout<<"\nElement Current Address Next Address Previous Address\n\n";
for(int i=0;i<count;i++,temp=temp->next)
{
cout<<" "<<temp->data<<" "<<temp<<" "<<temp->next<<" "<<temp->prev;
cout<<endl<<endl;
}
}
break;
default:cout<<"\nWrong entry!!";
}
cout<<"\a\nWANT TO CONTINUE?(Y/N):";
cin>>ch;
}
return 0;
}
void swap()
{
pl=first;
ql=last;
pf=pl;
qf=ql;
if(count==2 || count==3)
{
pf->prev=pf->next;
pf->next=nullptr;
qf->next=qf->prev;
qf->prev=nullptr;
first=qf;
last=pf;
return;
}
while((pf->next)!=(qf->prev) && (pf->next)!=qf)
{
pl=pl->next;
ql=ql->prev;
if(pf==first)
{
pl->prev=qf;
qf->next=pl;
qf->prev=nullptr;
first=qf;
ql->next=pf;
pf->prev=ql;
pf->next=nullptr;
last=pf;
}
else
{
pl->prev=qf;
(pf->prev)->next=qf;
ql->next=pf;
(qf->next)->prev=pf;
qf->prev=pf->prev;
pf->next=qf->next;
pf->prev=ql;
qf->next=pl;
}
pf=pl;
qf=ql;
}
if(count%2==0)
{
pf=pl->prev;
qf=ql->next;
pl->next=qf;
pl->prev=ql;
ql->next=pl;
ql->prev=pf;
pf->next=ql;
qf->prev=pl;
}
else
{
xf=pl->next;
pf=pl->prev;
qf=ql->next;
pl->next=qf;
pl->prev=xf;
ql->next=xf;
ql->prev=pf;
pf->next=ql;
qf->prev=pl;
xf->prev=ql;
xf->next=pl;
}
}
void visual()
{
system("cls");
cout<<"LOADING,PLEASE WAIT";
for(int j=0;j<8;j++)
{
cout<<".\a";
delay();
}
}
void delay()
{
for(int i=0;i<DELAY;i++)
continue;
}
No comments:
Post a Comment