DSA Lec 4
DSA Lec 4
Implementation
using Linked List
Stack
• A Stack is an ordered collection of
homogeneous data items. Data are entered into
a stack and are retrieved following the Last-
In-First-Out LIFO principle i.e the last
element to be inserted into the stack, will be
the first element to be outputted.
The stack data
structure
supports two
basic
operations,
which are
1. PUSH
2. POP
3. Peek
4. Display
A linked list is a collection of data items called nodes, where each node in
the list holds a pointer to the next node.
Step 5
•Take a temp node and initialize it
with top pointer.
•Now start traversing temp till it
encounters NULL.
•Simultaneously print the value of the
temp node.
After following the above steps you should get a code
similar to this, depending on the language used for
implementation.
//stack class, which will be instantiated by the client
public class Stack<Item> {
//reference to the first node in the stack
Node first = null;