import java.io.*;
import java.util.*;
class linklstud
{
public static void main(String ar[])throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("\nEnter No Of Elements To Be Added= ");
int no = Integer.parseInt(br.readLine());
LinkedList<String> ll = new LinkedList<String>();
for(int i = 0; i<no; i++)
{
System.out.print("\nEnter Student Name= ");
String str = br.readLine();
ll.add(str);
}
Iterator<String> it = ll.iterator();
System.out.println("\nContent Of LinkedList");
while(it.hasNext())
System.out.println("\t" + it.next());
ListIterator<String> lit = ll.listIterator(no);
System.out.println("\nContent Of LinkedList In Reverse Order");
while(lit.hasPrevious())
System.out.println("\t"+ lit.previous());
}
}
Post a Comment