GENERIC STACK USING LINKEDLIST COLLECTION CLASS
Wed May 29 2024 16:33:18 GMT+0000 (Coordinated Universal Time)
Saved by
@signup
import java.util.*;
class StackULLC{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
LinkedList l = new LinkedList();
int op=0;
System.out.println("1.Push\n2.Pop\n3.Display\n4.Exit");
while(op!=4){
System.out.print("Enter option:");
op = sc.nextInt();
switch(op){
case 1: System.out.println("Enter data: ");
int d = sc.nextInt();
l.addFirst(d);
break;
case 2: System.out.println("Poped: "+l.removeFirst());
break;
case 3:
LinkedList temp =new LinkedList(l);
while(!temp.isEmpty()){
System.out.print(temp.getFirst()+" ");
temp.removeFirst();
};System.out.println();
break;
case 4: break;
}
}
}
}
content_copyCOPY
Comments