class node
{
public int x;
public node next;
}
class Stack
{
public node top;
Stack()
{
top=null;
}
void push (int v)
{
node temp=new node();
temp.x=v;
temp.next=top;
top=temp;
}
int pop()
{
int v=top.x;
node temp=top;
top=top.next;
temp=null;
return v;
}
}
class StackList
{
public static void main(String as[])
{
Stack s1=new Stack();
s1.push(30);
s1.push(40);
s1.push(50);
System.out.println(s1.pop());
System.out.println(s1.pop());
System.out.println(s1.pop());
}
}
/* Output */
50
40
30
0 comments:
Post a Comment