Category Archives: Stack

Introduction to Stack

Introduction to Stack Stack is a linear data structure which follows LIFO i.e. Last In First Out. We can only access the topmost element. Consider the simple example of plates stacked over one another in canteen. The plate which is at the top is the first one to be removed (LIFO). The plate which has… Read More »

Next Greatest Element

Next Greatest Element(NGE) in an array Given an integer array, we need to print the next greatest element for each of the element. Example: {23,12,56,22,6,34} if this is the array, then for 12 the answer should be 56 and for 22 it is 34. Next greatest element in an array using stack: Algorithm to find next greatest element… Read More »

Reverse a String using Stack

Reverse a String using Stack Given a string, we need to reverse the string using a stack (or write a c/c++ program to reverse a sting using stack). Reversal of string using stack example: if the input is “Cloud Kaksha”, then output should be “ahskaK duolC” Algorithm to reverse a string using a stack: Create… Read More »