SlideShare a Scribd company logo
/* linked stack*/
#include <iostream>
using namespace std;
class Node
{
public :
int data;
Node *link;
};
class Lstack
{
private:
Node *Top;
public:
Lstack()
{
Top= NULL;
}
void Push(int value);
int Pop();
void Display();
};
void Lstack::Push(int value)
{
Node *Newnode;
Newnode = new Node;
Newnode->data=value;
Newnode->link = NULL;
if(Top==NULL)
{
Top=Newnode;
}
else
{
Newnode->link=Top;
Top=Newnode;
}
}
int Lstack::Pop()
{
Node* Temp=Top;
int popval;
if(Temp == NULL)
cout << "Empty List";
else
{
popval=Temp->data;
Top=Temp->link;
delete Temp;
}
return popval;
}
void Lstack::Display()
{
Node *temp = Top;
if(temp == NULL)
cout << "Empty List";
else
{
while(temp != NULL)
{
cout << temp->data << "t";
temp = temp->link;
}
}
cout << endl;
}
int main()
{
Lstack L1;
L1.Push(35);
L1.Push(45);
L1.Push(55);
cout<<"n"<<"Before Popping the values in stack : ";
L1.Display();
cout<<"Popped value is : "<<L1.Pop();
cout<<"n"<<"After Popping the values in stack: ";
L1.Display();
return 0;
}
Output:
Before Popping the values in stack : 55 45 35
Popped value is : 55
After Popping the values in stack: 45 35

More Related Content

PPTX
Data Structures and Agorithm: DS 06 Stack.pptx
PPT
Lec 4 Stack of Data Structures & Algorithms
PPTX
Link list
PPTX
Stacks in c++
PDF
Create a link list. Add some nodes to it, search and delete nodes fro.pdf
PPT
Link list part 2
PDF
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
PPTX
Linked list
Data Structures and Agorithm: DS 06 Stack.pptx
Lec 4 Stack of Data Structures & Algorithms
Link list
Stacks in c++
Create a link list. Add some nodes to it, search and delete nodes fro.pdf
Link list part 2
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
Linked list

Similar to Linked Stack program.docx (20)

PDF
Data Structures in C++I am really new to C++, so links are really .pdf
DOCX
EXP_2_stck implementation using linked list Code.docx
PPTX
Data Structure.pptx
PPTX
Revisiting a data structures in detail with linked list stack and queue
PPSX
Stacks fundamentals
PPT
Stack queue
PPT
Stack queue
PPT
Stack queue
PPT
Stack queue
PPT
Stack queue
PPT
Stack queue
PPT
Stack queue
PDF
#includeiostream #includecstdio #includecstdlib using na.pdf
PPTX
Stack and its applications
PPTX
PDF
In the class we extensively discussed a node class called IntNode in.pdf
DOCX
Bsf23006565 dsa 3rd assignment.docx............
DOCX
C++ Please write the whole code that is needed for this assignment- wr.docx
PPT
Algo>Stacks
PDF
04 stacks
Data Structures in C++I am really new to C++, so links are really .pdf
EXP_2_stck implementation using linked list Code.docx
Data Structure.pptx
Revisiting a data structures in detail with linked list stack and queue
Stacks fundamentals
Stack queue
Stack queue
Stack queue
Stack queue
Stack queue
Stack queue
Stack queue
#includeiostream #includecstdio #includecstdlib using na.pdf
Stack and its applications
In the class we extensively discussed a node class called IntNode in.pdf
Bsf23006565 dsa 3rd assignment.docx............
C++ Please write the whole code that is needed for this assignment- wr.docx
Algo>Stacks
04 stacks

Recently uploaded (20)

PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PPTX
Geodesy 1.pptx...............................................
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
DOCX
573137875-Attendance-Management-System-original
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PPT
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PPTX
Internet of Things (IOT) - A guide to understanding
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PPTX
Lecture Notes Electrical Wiring System Components
PPTX
OOP with Java - Java Introduction (Basics)
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PPTX
Construction Project Organization Group 2.pptx
PPTX
web development for engineering and engineering
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PPTX
UNIT 4 Total Quality Management .pptx
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
CYBER-CRIMES AND SECURITY A guide to understanding
Geodesy 1.pptx...............................................
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
573137875-Attendance-Management-System-original
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
Internet of Things (IOT) - A guide to understanding
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
Operating System & Kernel Study Guide-1 - converted.pdf
Lecture Notes Electrical Wiring System Components
OOP with Java - Java Introduction (Basics)
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
Construction Project Organization Group 2.pptx
web development for engineering and engineering
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
UNIT 4 Total Quality Management .pptx
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf

Linked Stack program.docx

  • 1. /* linked stack*/ #include <iostream> using namespace std; class Node { public : int data; Node *link; }; class Lstack { private: Node *Top; public: Lstack() { Top= NULL; } void Push(int value); int Pop(); void Display(); }; void Lstack::Push(int value) { Node *Newnode; Newnode = new Node; Newnode->data=value; Newnode->link = NULL; if(Top==NULL) { Top=Newnode; } else { Newnode->link=Top; Top=Newnode; } } int Lstack::Pop() { Node* Temp=Top; int popval; if(Temp == NULL) cout << "Empty List"; else { popval=Temp->data; Top=Temp->link; delete Temp; }
  • 2. return popval; } void Lstack::Display() { Node *temp = Top; if(temp == NULL) cout << "Empty List"; else { while(temp != NULL) { cout << temp->data << "t"; temp = temp->link; } } cout << endl; } int main() { Lstack L1; L1.Push(35); L1.Push(45); L1.Push(55); cout<<"n"<<"Before Popping the values in stack : "; L1.Display(); cout<<"Popped value is : "<<L1.Pop(); cout<<"n"<<"After Popping the values in stack: "; L1.Display(); return 0; } Output: Before Popping the values in stack : 55 45 35 Popped value is : 55 After Popping the values in stack: 45 35