Stack Using Linked List

Let us see in the below program how stack can be implemented using Linked List. #include <iostream>using namespace std;typedef struct node{ int data; struct node* next; }Node;class stack{private: Node* head;public: stack() { head = NULL; } ~stack() { while (NULL != head) { Node* temp = head; head = head ->next; delete temp; } } void push(int data) { Node* temp = new Node; temp->data = data; if (NULL == head) { head = temp; head->next = NULL; return; } temp->next = head; head = temp; } int pop() {…

Stack using fixed size array

Stack is one of the data structure that uses LIFO (Last In First Out) or FILO (First In Last Out) property i.e. element which is stored in last, will be out (read) first.Real life example of stack is stack of plates. Last plate put over the plates is the first plate that is removed or used. #include <iostream>using namespace std;const int MAX_INDEX = 50;  // Maximum index of array.const int MIN_INDEX  = -1; // Minimum index  of array.class stack{private: unsigned int arr[MAX_INDEX]; int top;public: stack() { top = MIN_INDEX; }…