Stack in C++ Using Linked List

Here you will learn about stack in C++ using a program example.

Stack is an abstract datatype which follows Last In First Out (LIFO) principle. Basically stack has two operations namely push and pop. 

push: inserting an element at the top of the stack

pop: removing an element from the top of the stack

Below code shows you how to implement stack in C++ using linked list data structure.

 

Program for Stack in C++

 

Output:

1.Push
2.Pop
3.Display
4.Exit
Enter your choice(1-4):1

Enter data:7
1.Push
2.Pop
3.Display
4.Exit
Enter your choice(1-4):1

Enter data:8
1.Push
2.Pop
3.Display
4.Exit
Enter your choice(1-4):3
8 7

1.Push
2.Pop
3.Display
4.Exit
Enter your choice(1-4):4

Category: DSA

11 thoughts on “Stack in C++ Using Linked List

  1. neha shrivastav

    its realiy so nice to use it . thanku so much for creating this beause it is helpfull to every one who are studing this subjest.. keep doing it and ALL THE BEST FOR UR BEST FUCTURE..

    Reply
  2. jen

    any u give a different program with with logic of getting queue using linked list ????????

    Reply
  3. Ananya

    I see the error.”function exit should have a a prototype”what I do

    Reply
  4. Sxd1234

    Though I have done it myself but it is very much similar to what you have written I am getting problem in showing the data where it is not showing the data entered the first time.

    Reply
  5. santhosh

    hi bro ….
    we need one programme on STACK
    STRUCT employee
    {
    int pno;
    char pname[20];
    }*ptr,*nptr,*top;

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.