Professional Documents
Culture Documents
#include<iostream>
class node
public:
int data;
node *next;
};
int main()
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
cin>>a[i];
node *first;
node *last;
node *temp;
first=new node();
first->data=a[0];
first->next=NULL;
last=first;
for(int i=1;i<n;i++)
{
temp=new node();
temp->data=a[i];
temp->next=NULL;
last->next=temp;
last=temp;
display(first);
deletedupli(first);
display(first);
while(n)
cout<<n->data<<" ";
n=n->next;
cout<<endl;
node *p;
p=n->next;
while(p)
if(n->data==p->data)
n->next=p->next;
delete p;
p=n->next;
else
n=n->next;
p=p->next;
#include<iostream>
class node
public:
int data;
node *next;
};
int main()
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
cin>>a[i];
}
node *first;
node *temp;
node *last;
first=new node();
first->data=a[0];
first->next=NULL;
last=first;
for(int i=1;i<n;i++)
temp=new node();
temp->data=a[i];
temp->next=NULL;
last->next=temp;
last=temp;
display(first);
node *p;
p=first;
int i=0;
int b[n];
while(p)
b[i]=p->data;
p=p->next;
i++;
p=first;
i--;
while(p)
{
p->data=b[i--];
p=p->next;
display(first);
while(n)
cout<<n->data<<" ";
n=n->next;
cout<<endl;
*/
class node
public:
int data;
node *next;
};
int main()
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
cin>>a[i];
node *first;
node *temp;
node *last;
first=new node();
first->data=a[0];
first->next=NULL;
last=first;
for(int i=1;i<n;i++)
temp=new node();
temp->data=a[i];
temp->next=NULL;
last->next=temp;
last=temp;
display(first);
node *r=NULL;
node *q=NULL;
while(first)
r=q;
q=first;
first=first->next;
q->next=r;
}
first=q;
display(first);
while(n)
cout<<n->data<<" ";
n=n->next;
cout<<endl;
#include<iostream>
class node
public:
int data;
node *next;
};
int main()
int n;
cin>>n;
int a[n];
cout<<"enter the data of the first linked list "<<endl;
for(int i=0;i<n;i++)
cin>>a[i];
node *first1;
node *temp;
node *last;
first1=new node();
first1->data=a[0];
first1->next=NULL;
last=first1;
for(int i=1;i<n;i++)
temp=new node();
temp->data=a[i];
temp->next=NULL;
last->next=temp;
last=temp;
display(first1);
int m;
cin>>m;
int b[m];
for(int i=0;i<m;i++)
cin>>b[i];
}
node* first2;
first2=new node();
first2->data=b[0];
first2->next=NULL;
last=first2;
for(int i=1;i<m;i++)
temp=new node();
temp->data=b[i];
temp->next=NULL;
last->next=temp;
last=temp;
display(first2);
node *p;
node *q;
p=first1;
while(p)
q=p;
p=p->next;
q->next=first2;
display(first1);
while(n)
{
cout<<n->data<<" ";
n=n->next;
cout<<endl;
class node
public:
int data;
node *next;
};
int main()
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
cin>>a[i];
node *first;
node *last;
node *temp;
first=new node();
first->data=a[0];
first->next=NULL;
last=first;
for(int i=1;i<n;i++)
temp=new node();
temp->data=a[i];
temp->next=NULL;
last->next=temp;
last=temp;
display(first);
int m;
cin>>m;
int b[m];
for(int i=0;i<m;i++)
cin>>b[i];
node *second;
second=new node();
second->data=b[0];
second->next=NULL;
last=second;
for(int i=1;i<m;i++)
temp=new node();
temp->data=b[i];
temp->next=NULL;
last->next=temp;
last=temp;
display(second);
node *third;
if(first->data<second->data)
third=last=first;
first=first->next;
last->next=NULL;
else
third=last=second;
second=second->next;
last->next=NULL;
if(first->data<second->data)
last->next=first;
last=first;
first=first->next;
last->next=NULL;
else
{
last->next=second;
last=second;
second=second->next;
last->next=NULL;
if(first)
last->next=first;
else
last->next=second;
display(third);
while(n)
cout<<n->data<<" ";
n=n->next;
cout<<endl;
class node
{
public:
int data;
node *next;
};
int main()
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
cin>>a[i];
node *first;
node *temp;
node *last;
first=new node();
first->data=a[0];
first->next=NULL;
last=first;
for(int i=1;i<n;i++)
temp=new node();
temp->data=a[i];
temp->next=NULL;
last->next=temp;
last=temp;
}
display(first);
last->next=first->next->next;
cout<<isloop(first)<<endl;
while(n)
cout<<n->data<<" ";
n=n->next;
cout<<endl;
node *p,*q;
p=q=n;
do
p=p->next;
q=q->next;
if(q!=NULL)
q=q->next;
else
}
while(p && q && p!=q);
if(p==q)
return "true";
else
return "false";
#include<iostream>
class node
public:
int data;
node *next;
};
int main()
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
cin>>a[i];
}
node *head;
node *temp;
node *last;
head=new node();
head=new node();
head->data=a[0];
head->next=NULL;
last=head;
for(int i=1;i<n;i++)
temp=new node();
temp->data=a[i];
temp->next=NULL;
last->next=temp;
last=temp;
last->next=head;
display(head);
node *p=n;
do
cout<<p->data<<" ";
p=p->next;
while(p!=head);
cout<<endl;
}
// inserting new node into the existing node in the circular linked list
#include <iostream>
class node
public:
int data;
node *next;
};
int main()
int n;
cin >> n;
int a[n];
cout << "enter the data of the nodes " << endl;
node *first;
node *last;
node *temp;
first->data = a[0];
first->next = NULL;
last = first;
{
temp = new node();
temp->data = a[i];
temp->next = NULL;
last->next = temp;
last = temp;
last->next = first;
cout << "display of circular linked list before inserting the new node " << endl;
display(first);
int pos, x;
cout << "enter the position where you want insert new node " << endl;
cout << "enter the data of the new node " << endl;
cin >> x;
cout << "display of the circular linked list after inserting the new node " << endl;
display(first);
node *p;
p = n;
do
p = p->next;
} while (p != n);
{
node *t;
t = new node();
t->data = x;
if (pos == 0)
t->next = n;
n = t;
else
n = n->next;
t->next = n->next;
n->next = t;
#include<iostream>
class node
public:
int data;
node *next;
};
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
cin>>a[i];
node *first;
node *temp;
node *last;
first=new node();
first->data=a[0];
first->next=NULL;
last=first;
for(int i=1;i<n;i++)
temp=new node();
temp->data=a[i];
temp->next=NULL;
last->next=temp;
last=temp;
last->next=first;
display(first);
int pos;
cout<<"enter the position of the node which you want to delete "<<endl;
cin>>pos;
if(pos==1)
first=deletefirst(first);
last->next=first;
else
deletenode(first,pos);
display(first);
node *p;
p=n;
do
cout<<p->data<<" ";
p=p->next;
while(p!=n);
cout<<endl;
node *p;
for(int i=0;i<pos-1;i++)
p=n;
n=n->next;
}
p->next=n->next;
delete n;
node *p;
p=n;
n=n->next;
delete p;
return n;