0% found this document useful (0 votes)
2 views

3.Stack using linked list

The document presents a C++ implementation of a stack using a linked list. It defines a Stack class with methods for pushing, popping, and displaying items in the stack. The main function provides a menu-driven interface for users to perform stack operations.

Uploaded by

ponni.world009
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

3.Stack using linked list

The document presents a C++ implementation of a stack using a linked list. It defines a Stack class with methods for pushing, popping, and displaying items in the stack. The main function provides a menu-driven interface for users to perform stack operations.

Uploaded by

ponni.world009
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

3.

Stack using linked list

#include<iostream.h>

#include<conio.h>

#include<stdlib.h>

struct node

int data;

struct node*link;

};

class Stack

node*top;

public:

Stack()

top=NULL;

void push()

node*temp=new node;

cout<<"\n Enter a item to push:";

cin>>temp->data;

temp->link=top;

top=temp;

void pop()
{

if (top==NULL)

cout<<"\n stack is empty";

return;

cout<<"\n Item poped is:"<<top->data;

top=top->link;

void show()

node*temp=top;

cout<<"\n Items available in stack \n";

while(temp!=NULL)

cout<<temp->data<<"\t";

temp=temp->link;

};

void main()

clrscr();

Stack s;

int ch;

while(1)

{
cout<<"\n stack operation usng linked list:";

cout<<"\n\t menu\n\t1.push\n\t2.pop\n\t3.show\n\t4.exit\n:";

cout<<"\n\tenter your choice:";

cin>>ch;

switch(ch)

case 1:

s.push();

break;

case 2:

s.pop();

break;

case 3:

s.show();

break;

case 4:

exit(0);

};

You might also like