Implement Stack using Linked List
Algorithm:
- In push operation add element at head of list (
head = new Node(data, head)
) - In pop operation, remove element from head of list
-
Node temp = head
head = head.getNext()
temp.setNext(null)
return temp.getData()
Latest Source Code:
Github: ListStack.java
Output:
40 30 20 10 Pop :40 Pop :30 Pop :300 200 100 20 10