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 *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;