import java.util.*;
import java.io.*;
import java.lang.*;
class lnknegv
{
public static void main(String ar[]) throws Exception
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter No Of Elements To Be Added: ");
int no = Integer.parseInt(br.readLine());
LinkedList ll = new LinkedList();
for(int i = 0; i<no; i++)
{
System.out.print("\nEnter "+(i+1)+" Element:");
int n = Integer.parseInt(br.readLine());
ll.add(n);
}
Iterator it = ll.iterator();
System.out.println("\nNegative Element");
while(it.hasNext())
{
int el;
el = it.next();
if(el<0)
System.out.println("\n"+el);
}
ll.removeLast();
System.out.println("\nAfter Deleting Last Record: ");
it = ll.iterator();
while(it.hasNext())
System.out.println("\n"+it.next());
}
}
Post a Comment