Sinle LL
Sinle LL
Sinle LL
html
In [ ]: #include<iostream>
using namespace std;
class node{
public:
int data;
node *next;
// pointer of node type
//as this pointer will point to the next node
node(int data=0){
this ->data=data;
this ->next=NULL;
}
};
}
temp1->next=temp;
temp->next=NULL;
}
1 of 6 23/11/23, 11:30
Untitled3 file:///home/pvg/Downloads/Untitled3(1).html
temp1->next=temp;
temp->next=temp2;
print(head1);
while(count<position){
temp=temp->next;
count++;
}
temp->data=d;
print(head);
2 of 6 23/11/23, 11:30
Untitled3 file:///home/pvg/Downloads/Untitled3(1).html
int main(){
/*
created an object of class node with name node1
and assigned a data value 10 to it .
created int the heap memory
*/
//initilizing the linked list
int a,b;
cout<<"enter the first element of the first linked list : ";
cin>>a;
cout<<"enter the first element of the another linked list : ";
cin>>b;
// using constructor
node *node1=new node(a);
node *node2=new node(b);
node *head1=node1;
node *head2=node2;
cout<<"\n*******---MENU---*******\n";
cout<<"0.exit\n1.insert at head\n2.insert at end\n3.insert inbetween\n4.updation o
int ch;
while(ch!=0){
cout<<"enter choice : ";
cin>>ch;
if(ch==1){
int z;
cout<<"\nin which linked list you want to insert ? \n";
cout<<"1.first\n2.second\n";
cin>>z;
if(z==1){InsertAtHead(head1);}
if(z==2){InsertAtHead(head2);}
}
3 of 6 23/11/23, 11:30
Untitled3 file:///home/pvg/Downloads/Untitled3(1).html
else if(ch==2){
int z;
cout<<"\nin which linked list you want to insert ? \n";
cout<<"1.first\n2.second\n";
cin>>z;
if(z==1){InsertAtEnd(head1);}
if(z==2){InsertAtEnd(head2);}
}
else if(ch==3){
int z;
cout<<"\nin which linked list you want to insert ? \n";
cout<<"1.first\n2.second\n";
cin>>z;
if(z==1){Insert(head1);}
if(z==2){Insert(head2);}
}
else if(ch==4){
int z;
cout<<"\nin which linked list ? \n";
cout<<"1.first\n2.second\n";
cin>>z;
if(z==1){updateNode(head1);}
if(z==2){updateNode(head2);}
}
else if(ch==5){
int z;
cout<<"\nin which linked list ? \n";
cout<<"1.first\n2.second\n";
cin>>z;
if(z==1){deleteNode(head1);}
if(z==2){deleteNode(head2);}
}
else if(ch==6){
int z;
cout<<"\nin which linked list ? \n";
cout<<"1.first\n2.second\n";
cin>>z;
if(z==1){print(head1);}
if(z==2){print(head2);}
}
else if(ch==7){
join(head1,head2);
}
else{
cout<<"pls select correct option (you had one job)!";
}
}
cout<<"thank you for using this program !!";
return 0;
}
/*output:
enter the first element of the first linked list : 11
enter the first element of the another linked list : 23
*******---MENU---*******
0.exit
1.insert at head
4 of 6 23/11/23, 11:30
Untitled3 file:///home/pvg/Downloads/Untitled3(1).html
2.insert at end
3.insert inbetween
4.updation of node
5.deletion of node
6.print linked list
7.Concatenate two lists
enter choice : 1
5 of 6 23/11/23, 11:30
Untitled3 file:///home/pvg/Downloads/Untitled3(1).html
6 of 6 23/11/23, 11:30