Practical No .2
Practical No .2
a) Stack ADT
b) Queue ADT
a) STACK ADT:-
#include <iostream>
class Stack {
private:
int top;
int maxSize;
public:
Stack() {
bool isFull() {
bool isEmpty() {
void push(int x) {
if (isFull()) {
cout << "Stack Overflow! Cannot push " << x << endl;
} else {
arr[++top] = x;
void pop() {
if (isEmpty()) {
} else {
cout << arr[top--] << " popped from stack." << endl;
void peek() {
if (isEmpty()) {
} else {
};
int main() {
Stack stack;
stack.push(10);
stack.push(20);
stack.push(30);
B) QUEUE ADT:-
#include <iostream>
class Queue {
private:
int front;
int rear;
int maxSize;
public:
Queue() {
front = -1;
rear = -1;
maxSize = 5;
bool isEmpty() {
bool isFull() {
}
void enqueue(int x) {
if (isFull()) {
cout << "Queue Overflow! Cannot enqueue " << x << endl;
} else {
front = 0;
arr[++rear] = x;
void dequeue() {
if (isEmpty()) {
} else {
cout << arr[front] << " dequeued from queue." << endl;
} else {
front++;
void peek() {
if (isEmpty()) {
} else {
}
};
int main() {
Queue queue;
queue.enqueue(10);
queue.enqueue(20);
queue.enqueue(30);
return 0;