Documente Academic
Documente Profesional
Documente Cultură
*; Insertion program
class Insertion
class Node
int m;
Node n;
public Node(int m)
this.m=m;
this.n=null;
int m;
Node n;
/*public Insertion(int m)
this.m=m;
this.n=null;
}*/
if(head==null)
head=newNode;
tail=newNode;
else
tail.n=newNode;
tail=newNode;
if(head==null)
head=newNode;
tail=newNode;
else
{
newNode.n=head;
head=newNode;
newNode.m=s;
ptr=head;
int c=1;
while(c<=p)
ptr=ptr.n;
c++;
ptr.n= newNode;
newNode.n=ptr;
newNode.m=s;
while(ptr.n!=null)
ptr=ptr.n;
newNode.n=null;
ptr.n= newNode;
Node Current=head;
int c=1;
if(head==null)
System.out.println("List is empty");
return;
while(Current!=null)
System.out.print(Current.m+" ");
Current=Current.n;
System.out.println();
}
int q=Integer.parseInt(br.readLine());
for(int i=1;i<=q;i++)
int f=Integer.parseInt(br.readLine());
obj.adNod(f);
obj.display();
int ch=Integer.parseInt(br.readLine());
int r=Integer.parseInt(br.readLine());
switch(ch)
case 1:
obj.instart(r);
obj.display();
break;
case 2:
obj.inmid(r,q);
obj.display();
break;
case 3:
obj.inend(r);
obj.display();
break;
default:
System.out.println("Wrong choice");