Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

C++ Stack Implementation, Exercises of Data Structures and Algorithms

The implementation of a stack data structure in c++ using two pointers. The user can choose to push, pop, or display the elements of the stack. The stack has a capacity of 10 elements.

Typology: Exercises

2011/2012

Uploaded on 07/30/2012

dhanvantari
dhanvantari 🇮🇳

2

(2)

48 documents

1 / 2

Toggle sidebar

Related documents


Partial preview of the text

Download C++ Stack Implementation and more Exercises Data Structures and Algorithms in PDF only on Docsity! #include<conio.h> #include<iostream.h> void push (int*,int*); void pop (int*,int*); void main () { int choice; int stack[10],top=-1; clrscr(); cout<<"Enter Your choice\n\t--> To push enter:\t1\n\t--> To pop enter:\t2\n\t--> To Display enter:\t3\n\t--> To exit enter:\t4\n"; cin>>choice; while (choice!=4) { switch(choice) { case 1: push(&stack[top+1],&top); break; case 2: pop(&stack[top],&top); break; case 3: for (int i=0;i<=top;i++) { cout<<stack[i]<<" "; } cout<<"\n"; break; default: cout<<"Wrong choice!!! please enter again\n"; break; } cout<<"\nEnter choice:\t"; cin>>choice; } } void push (int *st,int *t) { int input; if (*t>8) { cout<<"\nThe stack is full\n"; } else { cout<<"Enter the number you want to push:\t"; cin>>input; *t=*t+1; *st=input; st++; docsity.com
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved