Code:
#include<iostream>
#include<stdio.h>
using namespace std;
struct NODE{
int val;
NODE *next;
NODE *per;
};
class list{
private:
NODE *head;
NODE *current;
public:
list(){
head=current=NULL;
}
void insert(){
NODE *newnode=new NODE;
cout<<"ENTER NODE VALUE:";
cin>>newnode->val;
newnode->next=NULL;
newnode->per=NULL;
if(head==NULL){
head=current=newnode;
}
else{
current->next=newnode;
newnode->per=current;
current=newnode;
newnode->next=NULL;
}
}
void end(){
NODE *newnode2=new NODE;
cout<<"ENTER VALUE FOR END:";
cin>>newnode2->val;
current->next=newnode2;
newnode2->per=current;
current=newnode2;
newnode2->next=NULL;
}
void show(){
NODE *t;
t=head;
while(t->next!=NULL){
t=t->next;
cout<<t->val;
}
cout<<"\n THE REVERSE OUTPUT:"<<endl;
NODE *pt;
pt=current;
while(pt->per!=NULL){
cout<<pt->val;
pt=pt->per;
}
}
void show1(){
NODE *t;
t=head;
while(t->next!=NULL){
cout<<t->val;
t=t->next;
}
}
void begning(){
NODE *newnode1=new NODE;
cout<<"ENTER VALUE FOR FIRST:";
cin>>newnode1->val;
newnode1->next=head;
head->per=newnode1;
newnode1->per=NULL;
head=newnode1;
}
void middle(){
NODE *newnode3=new NODE;
int m;
cout<<"ENTER VALUE FOR MIDDLE:";
cin>>newnode3->val;
cout<<"ENTER NTH POSISTION:";
cin>>m;
NODE *any;
any=head;
for(int i=1;i<m-1&&any!=NULL;i++){
any=any->next;
}
NODE *any2;
any2=newnode3;
any2->next=current;
any2->per=any;
current->per=newnode3;
any->next=any2;
current->next=NULL;
}
void delet(){
int d;
cin>>d;
if(d==1){
cout<<"FIRST NODE DELETE:";
NODE *temp1=head;
NODE* temp2;
temp2=temp1->next;
head=temp2;
delete (temp1);
}
if(d==2){
int n;
NODE *temp1=head;
cout<<"ENTER WHAT IS NUMBER YOU WANT DELETE:";
cin>>n;
NODE* temp2=current;
while(temp1->next!=NULL){
if(temp1->val==d){
temp2=temp1->next;
current=temp1;
temp1->next=NULL;
delete(temp2);
}
temp1=temp1->next;
}
}
if(d==5){
int n1;
cout<<"ENTER WHAT IS NUMBER YOU WANT DELETE:";
cin>>n1;
NODE *any1;
any1=head;
while(any1->next!=NULL)
{
if(any1->val==n1){
any1->next=current;
current->per=any1;
}
any1=any1->next;
}
}
}
void show_start(){
NODE *t1;
t1=head;
while(t1->next!=NULL){
cout<<t1->val;
t1=t1->next;
}
cout<<"\nDESENDING OF FIRST NODE:\n";
NODE *pt1;
pt1=current;
while(pt1->per!=NULL){
cout<<pt1->val;
pt1=pt1->per;
}
}
void del(){
NODE *d;
d=head;
d=d->next;
delete d;
}
};
int main(){
int a,s;
list l7;
cout<<"ENTER 1 FOR CREATE LINK LIST:";
cin>>a;
if(a==1) {
cout<<"LIST CREATED:"<<endl;
cout<<"CHOSE OPTION OF INSERT:\n";
cout<<"-->ENTER 2 FOR END POINT:\n";
cout<<"-->ENTER 3 FOR FIRST POINT:\n";
cout<<"-->ENTER 5 FOR INSERT MIDDLE POINT:\n";
cout<<"-->ENTER 4 FOR BACK\n";
cin>>a;
if(a==2){
list l,l2;
l.insert();
l.insert();
l.end();
l.show();
cout<<"\n -->UPDATE VALUE:\n";
l2.insert();
l2.insert();
l2.end();
l2.show();
cout<<"\n PREE 2 FOR DELETE NUMBER :";
l2.delet();
l2.show1();
cout<<"your swap is:";
l7=l;
l=l2;
cout<<"\n BEFOR UPDATE VALUE SWAP:\n";
l.show1();
l2=l7;
cout<<"\n AFTER UPDATE VALUS SWAP:\n";
l2.show1();
}
else{
if(a==3){
list l3,l4;
l3.insert();
l3.insert();
l3.begning();
l3.show_start();
cout<<"-->UPDATE VALUE:\n";
l4.insert();
l4.insert();
l4.begning();
l4.show_start();
cout<<"\nDELETE ELMENT:";
l4.delet();
l4.show_start();
cout<<"\n SWAPING PROCCES :";
l7=l3;
l3=l4;
cout<<"\n BEFOR UPDATE VALUE SWAP:\n";
l3.show1();
l4=l7;
cout<<"\n AFTER UPDATE VALUS SWAP:\n";
l4.show1();
}
else{
if(a==5){
list l5,l6;
l5.insert();
l5.insert();
l5.insert();
l5.insert();
l5.middle();
l5.show();
cout<<"\n -->UPDATE VALUE:\n";
l6.insert();
l6.insert();
l6.insert();
l6.insert();
l6.middle();
l6.show1();
cout<<"\n PREE 5 FOR DELETE NUMBER :";
l5.delet();
l5.show1();
cout<<"\n SWAPING PROCCES :";
l7=l5;
l5=l6;
cout<<"\n BEFOR UPDATE VALUE SWAP:\n";
l5.show1();
l6=l7;
cout<<"\n AFTER UPDATE VALUS SWAP:\n";
l6.show1();
}
}
}
cout<<"-->ENTER 4 FOR BACK:";
cin>>a;
if(a==4){
cout<<"-->ENTER 2 FOR END POINT:\n";
cout<<"-->ENTER 3 FOR FIRST POINT:\n";
cout<<"-->ENTER 5 FOR INSERT MIDDLE POINT:\n";
cin>>a;
}
if(a==2){
list l,l2;
l.insert();
l.insert();
l.end();
l.show();
cout<<"\n -->UPDATE VALUE:\n";
l2.insert();
l2.insert();
l2.end();
l2.show();
cout<<"\n PREE 2 FOR DELETE NUMBER :";
l2.delet();
l2.show1();
cout<<"\n SWAPING PROCCES :";
l7=l;
l=l2;
cout<<"\n BEFOR UPDATE VALUE SWAP:\n";
l.show1();
l2=l7;
cout<<"\n AFTER UPDATE VALUS SWAP:\n";
l2.show1();
if(a==4){
cout<<"-->ENTER 3 FOR FIRST POINT:\n";
cout<<"-->ENTER 5 FOR INSERT MIDDLE POINT:\n";
cin>>a;
}
}
else{
if(a==3){
list l3,l4;
l3.insert();
l3.insert();
l3.begning();
l3.show_start();
cout<<"-->UPDATE VALUE:\n";
l4.insert();
l4.insert();
l4.begning();
l4.show_start();
cout<<"\nDELETE ELMENT:";
l4.delet();
l4.show_start();
cout<<"\n SWAPING PROCCES :";
l7=l3;
l3=l4;
cout<<"\n BEFOR UPDATE VALUE SWAP:\n";
l3.show1();
l4=l7;
cout<<"\n AFTER UPDATE VALUS SWAP:\n";
l4.show1();
cout<<"-->ENTER 4 FOR BACK:";
cin>>a;
if(a==4){
cout<<"-->ENTER 2 FOR END POINT:\n";
cout<<"-->ENTER 5 FOR INSERT MIDDLE POINT:\n";
cin>>a;
}
}
else{
if(a==5){
list l5,l6;
l5.insert();
l5.insert();
l5.insert();
l5.insert();
l5.middle();
l5.show();
cout<<"\n -->UPDATE VALUE:\n";
l6.insert();
l6.insert();
l6.insert();
l6.insert();
l6.middle();
l6.show();
cout<<"\n PREE 2 FOR DELETE NUMBER :";
l5.delet();
l5.show();
cout<<"\n SWAPING PROCCES :";
l7=l5;
l5=l6;
cout<<"\n BEFOR UPDATE VALUE SWAP:\n";
l5.show1();
l6=l7;
cout<<"\n AFTER UPDATE VALUS SWAP:\n";
l6.show1();
cout<<"-->ENTER 4 FOR BACK:";
cin>>a;
if(a==4){
cout<<"-->ENTER 2 FOR END POINT:\n";
cout<<"-->ENTER 3 FOR FIRST POINT:";
cin>>a;
}
}
}
}
}
}
0 Comments