Scholarship Wing - The Scholarship Support System

https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiB9j2UBxkCsDjsu7MKporeWjwD4xuSEiku15SDflZ9PBoo1q0SkCnhQbDPql_atk9R3bcfuKbkNCBJi9AbJXwPT37hjtevVOTXuGkjD9AlhrilDEay03rBKKi0q9PEzIJ6lLbxRui-GHO5cu6hpgBc2gxtGDad0W6akHuzXke33x1348mYxd1rA_vOfw/s1600/scholarship-wing-logo.png

This is default featured slide 1 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 2 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 3 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 4 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 5 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

Monday, October 11, 2021

Stacks Using Linked list Data structures using C++

 //**************** stack implimentation using linked lists************//
#include<iostream>
using namespace std;
class stack
{
public:
int data;
stack* link;
stack(int d)
{
data=d;
link=NULL;
}
};
void display(stack* &top)
{
stack* temp=top;
temp=top;
while(temp->data!=NULL)
{
cout<<temp->data<<"<--";
temp=temp->link;
}
cout<<endl;
} void pop(stack* &top)
{
stack*temp=top;
temp=top;
if(top==NULL)
{
cout<<"Cant b poped"<<endl;
}
else
{
temp=top;
top=top->link;
cout<<temp->data<<"poped";
delete temp;
}
cout<<"poped"<<endl;
display(top);
}
void push(stack* &top)
{
int data;
cout<<"Enter the data into stack"<<endl;
cin>>data;
stack* n=new stack(data);
if(top==NULL)
{
top=n;
}
else
{
n->link=top;
top=n;
cout<<data<<" pushed to stack"<<endl;
}
}
void peek(stack* & top)
{
if(top==NULL)
{
cout<<" top is empty"<<endl;
}
else
{
cout<<top->data<<":is peak element "<<endl;
}
display(top);
}
int main()
{
stack*top=NULL;
int ch;
do
{

cout<<"Enter your choicce"<<endl;
cout<<"\n 1=push \n 2= pop \n 3= peek \n 4= display"<<endl;
cin>>ch;
switch(ch)
{
case 1:
push(top);
break;

case 2:
pop(top);
break;
case 3:
peek(top);
break;
case 4:
display(top);
break;
}
cout<<"MAIn: press 1 to cntinue"<<endl;
cin>>ch;
}while(ch==1);
return 0;
}