



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
ABOUT THE STACK AND THEIR PROPERTY. hOW TO INSERT ,DELETE THE THE STACK QUEQE
Typology: Lab Reports
1 / 7
This page cannot be seen from the preview
Don't miss anything!




Stack #include
cout << "Stack size is: " << stk.size() << endl; bool loop = true; while(loop){ printMenu(); cout << "Enter your choice" << endl; cin >> ch; switch(ch){ case 1: // Push cout << "Enter the element to push: "; cin >> num; stk.push(num); cout << "Stack size is: " << stk.size() << endl; break; case 2: // Pop stk.pop(); cout << "Stack size is: " << stk.size() << endl; break; case 3: // Peek num = stk.peek(); cout << "Peeking : " << num << endl; break; case 4:
// at first top is pointing nothing top = - 1; } void Stack::push(int n){ // Check whether the stack is full if(isFull()){ cout << "Cannot push new element. Stack full" << endl; return; } top++; *(base + top) = n; cout << "New element has been pushed successfully" << endl; } void Stack::pop(){ if(isEmpty()){ cout << "Cannot pop element. Stack empty" << endl; return; } int poppedValue = *(base + top); top--; cout << poppedValue << " popped." << endl; }
bool Stack::isFull(){ if(size() == total_capacity){ return true; } return false; } int Stack::size(){ return top + 1; } bool Stack::isEmpty(){ if(size() < 1){ return true; } return false; } int Stack::peek(){ if(isEmpty()){ cout << "Cannot peek. Stack empty." << endl; } return *(base + top); }