You are on page 1of 3

#include<iostream>

using namespace std;


const int Size = 100;
class Array_stack
{
//initilize an array and top varieble as private member.

int stack[Size], top;


public:

//set top pointer on (-1) in constructor.


Array_stack() {

top = -1;
}

//function to check if stack is full or not.

bool IsFull() {
return top == (Size - 1);
}

//function to check if stack is Empty or not.

bool IsEmpty() {
return top == -1;
}

//function to Add Elements to Stack.

void Push(int value) {


if (!IsFull())
{
top++;
stack[top] = value;
cout << stack[top] << " Element Succesfully Added to Stack.\n";
}
else {
cout << "Stack is full,Push operation can't be done";
}
}

//function to Remove Elements from Stack.

int Pop() {
if (!IsEmpty()) {
cout <<" Removed Ellement from Stack is: ";
return stack[top];
}
else {
cout << "Stack is Empty,Pop operation can't be done";
}
}

//function to Print Stack Elements.

void Print() {
for (int i = top; i >=0 ; i--)
{
cout << i << " Ellement: " << stack[i] << endl;
}
}

//function to return Number of Empy Cells on Stack.

int Empty_Stack_Cells()
{
return (Size - top) - 1;
}

//function to return Number of Full Cells on Stack.

int Full_Stack_Cells() {
return top + 1;
}
};

class Stack_node
{
public:
int data;
Stack_node* next;
};
class linked_list_Stack
{
Stack_node *top;
public:
linked_list_Stack() {
top = NULL;
}
bool IsEmpty() {
return top == NULL;
}
void Push(int Value) {
Stack_node* newnode;
newnode = new Stack_node;
newnode->data = Value;
if (!IsEmpty()) {
newnode->next = top;
top = newnode;
}
else {
newnode->next = NULL;
}
cout << "Insertion is Done SuccesFully.\n";
}
void Pop() {
Stack_node* temp = top;
cout << "Removed Ellement from Stack is " << temp->data << endl;
top = temp->next;
delete temp;
}
void Print() {
Stack_node* temp = top;
while (temp->next != NULL) {
cout << temp->data << endl;
temp = temp->next;
}
cout << temp->data << endl;
}
};

void main() {

You might also like