Vous êtes sur la page 1sur 3

7/24/2015

C++:StackUsingLinkedListC++Programs

C++Programs
Home

C/C++Programs

DownloadeBook

AskQuestions

C/C++Questions

JavaQuestions

C++:StackUsingLinkedList
March6,2013Bytechgopal

Contact

Login

Username

C++programforstackusinglinkedlistwithoperationpush,pop,insert,deleteusingclassofnode&
stack

WhatisStack?

Password

RememberMe
LogIn
Register
LostPassword

GetFreeUpdates.Enteryouremail
address:

Subscribe

Stacksareatypeofcontaineradaptor,specificallydesignedtooperateinaLIFOcontext(lastinfirst
out),whereelementsareinsertedandextractedonlyfromtheendofthecontainer.

OperationOnStack:
Create
Insert
Delete
Display

Hereiscodeforstackusinglinkedlistinc++:
//StackByGopalTathe
#include<iostream>
usingnamespacestd
charch
classnode{ //ClassNodeWhichWillActasNodeOfSLL
public:
intd
node*next
node(intdata){ //ParametricConstructor
next=NULL
d=data
}
}
classstack{
node*top //Createhn&cnobjectsofnodeclass
public:
stack(){
top=NULL //MakehnasNull
}
voidpush(int) //ToCreateSLL
intpop()
voiddis() //TodisplaySLL
intemp()
}
intstack::pop(){
if(emp()==1){
cout<<"\nUnderflow"
return1
}
else{
node*p=top
top=top>next
intx=p>d
deletep
returnx
}
}
voidstack::push(intd1){
node*p=newnode(d1)
p>next=top
top=p
}
voidstack::dis(){
node*p=top
while(p!=NULL){ //ItwillmoveSLLuntilItdoesn'tfoundNULL
cout<<p>d<<"\n"

http://cppprograms.com/2013/03/stacklinkedlist/

Topics

C/C++Programs
DataStructures
DownloadeBook
General
Tutorials

ConnectWithUs

CPPPrograms
145likes

LikePage

Share

Bethefirstofyourfriendstolikethis

1/3

7/24/2015

C++:StackUsingLinkedListC++Programs

cout<<p>d<<"\n"
p=p>next
}
}
intstack::emp(){
if(top==NULL){
return1
}
else{
return0
}
}
intmain(){
stacko
intd1,i,ch1
do{
cout<<"\n1:CreateStack"
cout<<"\n2:Empty"
cout<<"\n3:Pop(Delete)"
cout<<"\n4:Print"
cout<<"\n5:Exit"
cout<<"\nEnterURChoice"
cin>>ch1
switch(ch1){
case1:
do{
cout<<"\nEnterData"
cin>>d1
o.push(d1)
cout<<"\nDOUWANTTOCONTINUE...EnterYourChoiceyORY\n"
cin>>ch
}while(ch=='y'||ch=='Y')
cout<<"\n"
o.dis()
break
case2:
if(o.emp()==1){
cout<<"\nEmptyStack"
}
else{
cout<<"\nNotEmpty"
}
break
case3:
cout<<o.pop()<<"ispoped\n"
o.dis()
break
case4:
o.dis()
break
case5:
break
}
}while(ch!=5)
return(0)
}

Comments
kamalsays
June3,2013at6:30pm

thanks,itwasaverywellwrittencode

LogintoReply

{http://cruznday.centerblog.net/1tipstodealwithpersonalinjurysays
September16,2014at4:09pm

Thesesaresalespeoplewhoworkonacommissionbasis.They
willguideyouthroughoutthecaseaswellassearchforevidencetosupportyou.
Everydaysomeoneisinvolvedorinjuredinacaraccident.

LogintoReply

Trackbacks
C++ProgramListsays:
December30,2014at1:37pm

[]PDFFileName:C++:stackusinglinkedlistcppprogramsSource:cppprograms.com
DOWNLOAD[]

LogintoReply

C++ProgramStackUsingArraysays:
January4,2015at12:39am

http://cppprograms.com/2013/03/stacklinkedlist/

2/3

7/24/2015

C++:StackUsingLinkedListC++Programs

January4,2015at12:39am

[]PDFFileName:C++:stackusinglinkedlistcppprogramsSource:cppprograms.com
DOWNLOAD[]

LogintoReply

LeaveaReply
Youmustbeloggedintopostacomment.

Copyright2015

http://cppprograms.com/2013/03/stacklinkedlist/

3/3

Vous aimerez peut-être aussi