class Stack
{
Node top;
int height;
class Node
{
int value;
Node next;
Node(int value)
{
this.value = value;
}
}
Stack(int value)
{
Node newNode = new Node(value);
top = newNode;
height=1;
}
public void print()
{
Node temp = top;
while(temp!=null)
{
System.out.println(temp.value);
temp = temp.next;
}
}
public void getTop()
{
System.out.println("Top: "+top.value);
}
public void getHeight()
{
System.out.println("Height: "+height);
}
public void push(int value)
{
Node newNode = new Node(value);
if(height==0)
{
top = newNode;
}
else
{
newNode.next = top;
top = newNode;
}
height++;
}
public Node pop()
{
if(height == 0)
{
return null;
}
Node temp = top.next;
top.next = null;
top = temp;
height--;
return temp;
}
}
class Main {
public static void main(String[] args) {
Stack myStack = new Stack(1);
myStack.push(2);
myStack.push(3);
myStack.push(4);
myStack.pop();
myStack.print();
// myStack.getTop();
// myStack.getHeight();
// System.out.println("Hello World!");
}
}