Wednesday, 1 Dec 2021
Category: cpp-stack-functions

#include using namespace std;  class Stack {private:            int Max = 5;              int* arr = new int(Max);              int minEle = 0;              int top = 0;  public:            bool empty()    {        if (top

Program to insert an element at the Bottom of a StackGiven a stack S and an integer N, the task is to insert N at the bottom of the stack.Examples:Input: N = 7S = 1

Reversing a Stack with the help of another empty StackGiven a Stack consisting of N elements, the task is to reverse the Stack using an extra stack.Examples:Input: stack = {1, 2, 3, 4, 5}Output:12345Explanation:Input Stack:54321Reversed Stack:12345Input: stack = {1, 3, 5, 4, 2}Output:13542Approach: Follow the steps below to solve the problem:Below is the implementation of […]

Minimize length of a string by removing pairs of consecutive increasing or decreasing digitsGiven a numeric string S consisting of N digits, the task is to find the minimum length of the string that can be formed by repeatedly removing pairs of adjacent consecutive characters arranged in either increasing or decreasing order.Examples:Input: S = “12213”Output: […]

Minimize length of a string by removing pairs of consecutive increasing or decreasing digitsGiven a numeric string S consisting of N digits, the task is to find the minimum length of the string that can be formed by repeatedly removing pairs of adjacent consecutive characters arranged in either increasing or decreasing order.Examples:Input: S = “12213”Output: […]

Remove trailing zeros from the sum of two numbers ( Using Stack )Given two numbers A and B, the task is to remove the trailing zeros present in the sum of the two given numbers using a stack.Examples:Input: A = 124, B = 186Output: 31Explanation: Sum of A and B is 310. Removing the trailing […]