Professional Documents
Culture Documents
*;
LL l=new LL();
int ch=sc.nextInt();
while(ch!=7)
if(ch==1)
int data=sc.nextInt();
l.insertfront(data);
l.display();
else if(ch==2)
{
System.out.print("\nEnter data to be added at end=");
int data=sc.nextInt();
l.insertatend(data);
l.display();
else if(ch==3)
int data=sc.nextInt();
int pos=sc.nextInt();
l.insertatmiddle(data,pos);
l.display();
else if(ch==4)
l.deletefront();
l.display();
else if(ch==5)
l.deleteend();
l.display();
else
{
int pos=sc.nextInt();
l.deleteatmiddle(pos);
l.display();
System.out.print("Next choice=");
ch=sc.nextInt();
l.reverse();
l.display();
class LL
Node head;
class Node
int data;
Node next;
Node(int data)
{
this.data=data;
next=null;
nn.next=head;
head=nn;
Node temp=head;
while(temp.next!=null)
temp=temp.next;
temp.next=nn;
nn.next=null;
{
Node nn=new Node(data);
Node temp=head;
Node prev=null;
for(int i=0;i<=pos-1;i++)
prev=temp;
temp=temp.next;
prev.next=nn;
nn.next=temp;
void deletefront()
head=head.next;
void deleteend()
Node temp=head;
while(temp.next.next!=null)
temp=temp.next;
temp.next=null;
Node temp=head;
Node prev=null;
for(int i=0;i<=pos-1;i++)
prev=temp;
temp=temp.next;
prev.next=temp.next;
void display()
Node temp=head;
while(temp!=null)
System.out.print(temp.data+"->");
temp=temp.next;
System.out.print("null\n");
void reverse()
Node prev=head;
Node curr=head.next;
Node n=head.next.next;
while(n!=null)
curr.next=prev;
prev=curr;
curr=n;
n=n.next;
head.next=null;
curr.next=prev;
head=curr;