package test;
import java.util.*;
public class linklist<s> {
public node<s> head=null;
public void add()
{Scanner sc=new Scanner(System.in);
s a=(s) sc.nextLine();
head=new node<s>(a,head);
}
public void insert(int n,s b)
{node<s> temp=head;
for(int i=0;i<n;i++)
{
temp=temp.next;
}
temp.next=new node<s>(b,temp.next);
}
public void show()
{node<s> temp = head;
while(temp!=null)
{
System.out.println(temp.data);
temp=temp.next;
}
}
public class node<s>
{
s data;
node<s> next;
node(s a,node next)
{
this.data=(s) a;
this.next=next;
}
}
public static void main(String[] arg)
{
linklist<String> l=new linklist<String>();
for(int i=0;i<3;i++)
{
l.add();
}
l.insert(2,"d");
l.show();
}
}
import java.util.*;
public class linklist<s> {
public node<s> head=null;
public void add()
{Scanner sc=new Scanner(System.in);
s a=(s) sc.nextLine();
head=new node<s>(a,head);
}
public void insert(int n,s b)
{node<s> temp=head;
for(int i=0;i<n;i++)
{
temp=temp.next;
}
temp.next=new node<s>(b,temp.next);
}
public void show()
{node<s> temp = head;
while(temp!=null)
{
System.out.println(temp.data);
temp=temp.next;
}
}
public class node<s>
{
s data;
node<s> next;
node(s a,node next)
{
this.data=(s) a;
this.next=next;
}
}
public static void main(String[] arg)
{
linklist<String> l=new linklist<String>();
for(int i=0;i<3;i++)
{
l.add();
}
l.insert(2,"d");
l.show();
}
}
No comments:
Post a Comment