hello i m jayesh.,.....can somebody help me with this......
import java.io.*;
class StackNode
{
Object info;
StackNode next=null;
StackNode prev=null;
StackNode(Object el)
{
info=el;
}
}
class Stack
{
StackNode head,tail;
Stack(){}
boolean isEmpty()
{ return head==null;}
void push(Object el)
{
if(isEmpty())
head=tail=new StackNode(el);
else
{
tail.next=new StackNode(el);
tail.prev=tail;
tail=tail.next;
}
}
Object pop()
{
Object el;
el=tail.info;
tail=tail.prev;
return el;
}
Object peek()
{ return tail.info;}
}
class StackUsingLinkedList
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int x,in;
Stack s=new Stack();
System.out.println("STACK IMPLEMENTATION USING INT ARRAY");
do
{
System.out.println("\n\nENTER CHOICE\n1.PUSH 2.POP 3.PEEK 4.EXIT");
x=Integer.parseInt(br.readLine());
switch(x)
{
case 1:
System.out.println("Enter an integer");
in=Integer.parseInt(br.readLine());
s.push(in);
break;
case 2:
if(!s.isEmpty())
System.out.println("Element at the top of the stack : "+s.pop());
else
System.out.println("Stack is Empty");
break;
case 3:
if(!s.isEmpty())
System.out.println("Element at the top of the stack : "+s.peek());
else
System.out.println("Stack is Empty");
break;
case 4:
break;
}
}
while(x!=4);
}
}