Stack implementation of linked list. Using C++ programming.
Stack implementation of the linked list. It is a data structure and the stack follows the last in first out technique. Using C++
Definition:
Stack implementation of the linked list. It is a data structure and the stack follows last in first out technique. And in link list it has a head node and a null followed by a next node using reference pointer it maps the address of the nodes.
Algorithm:
Creating a node:
- Start
- Define a structure named as node
- It must contain data and the next pointer
- Set head with the node as datatype
- Set data of head as-1 and next pointer as NULL
- Stop
Creating a stack/Pushing elements into the stack
- Start
- Read the element to be pushed
- Create a node(temp) to store the new element
- Set x as temp’s data
- Set the temp’s next as head’s next
- Make head’s next to point to temp
- Stop
Display
- Start
- Set I as a structure object
- Set I to next pointer of head
- Display data of I and each time increment ptr of i
- Continue this process until i is not null
- Stop
Delete/Pop the elements from the stack
- Create a new node named as t
- Point t to head’s next
- Point head’s next to t’s next
Is empty
- Start
- If the next of head is NULL then return 1 else return 0
- Stop
For Example:
push(55),push(66),push(77),push(88),push(99),pop(),display()
OUTPUT:
55 66 77 88 [99 is poped out] remaining is displayed.
Project Files
/
Loading...
| .. | ||
| This directory is empty. | ||