0% found this document useful (0 votes)
2 views3 pages

Expt 4 Printout

The document presents a C++ program that implements a stack data structure with basic operations such as push, pop, and display. It includes a class definition for the stack, methods for handling overflow and underflow conditions, and a main function demonstrating the stack's functionality. The output shows the results of pushing and popping elements from the stack.

Uploaded by

dnyanesh.agale
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

Expt 4 Printout

The document presents a C++ program that implements a stack data structure with basic operations such as push, pop, and display. It includes a class definition for the stack, methods for handling overflow and underflow conditions, and a main function demonstrating the stack's functionality. The output shows the results of pushing and popping elements from the stack.

Uploaded by

dnyanesh.agale
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

EXPERIMENT NO: 04

Name : Agale Dnyanesh Nandkishor


Roll No. : 1
#include <iostream>
using namespace std;
class Stack {
int *arr, top, size;
public:
Stack(int s) : size(s), top(-1){
arr = new int[size];jhuiefhoief
}
~Stack(){
delete[]arr;
}
void push(int val){
if(top== size-1)
cout<<”Overflow\n”;
else{
arr[++top] = val;
cout << “Element”<< val << “is pushed\n”;
}
}
Void pop(){
if(top== -1)
cout<<”Underflow\n”;
else{
cout << “Element”<< arr[top]<< “is popped\n”;
top--;
}
}

void display() {
cout<< “Stack:”;
for(int I =0; i<=top; i++){
cout<< arr[i] << “ ”;
}
cout<<endl;
}
};

int main(){
Stack s(3);
s.push(10);
s.push(20);
s.push(30);
s.display();
s.pop();
s.display();
return 0;
}

OUTPUT:
Element 10 is pushed.
Element 10 is pushed.
Element 10 is pushed.
Element 10 is pushed.
Stack: 10 20 30
Element 30 is popped.
Stack: 10 20

You might also like