Coders Packet

Stack implementation of linked list. Using C++ programming.

By Srivenurajulu G

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:

  1. Start
  2. Define a structure named as node
  3. It must contain data and the next pointer
  4. Set head with the node as datatype
  5. Set data of head as-1 and next pointer as NULL
  6. Stop

Creating a stack/Pushing elements into the stack

  1. Start
  2. Read the element to be pushed
  3. Create a node(temp) to store the new element
  4. Set x as temp’s data
  5. Set the temp’s next as head’s next
  6. Make head’s next to point to temp
  7. Stop

Display

  1. Start
  2. Set I as a structure object
  3. Set I to next pointer of head
  4. Display data of I and each time increment ptr of i
  5. Continue this process until i is not null
  6. Stop

Delete/Pop the elements from the stack

  1. Create a new node named as t
  2. Point t to head’s next
  3. Point head’s next to t’s next

Is empty

  1. Start
  2. If the next of head is NULL then return 1 else return 0
  3. 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.

Download project

Reviews Report

Submitted by Srivenurajulu G (Srivenurajulu)

Download packets of source code on Coders Packet