Category: cpp-stack

Calculate sum of the array generated by given operations

Calculate sum of the array generated by given operations Given an array arr[] consisting of N strings, the task is to find the total sum of the array brr[] (initially empty) constructed by performing following operations while traversing the given array arr[]: Examples: Input: arr[] = {“5”, “2”, “C”, “D”, “+”}Output: 30Explanation:While traversing the array […]

Continue Reading

Preorder, Postorder and Inorder Traversal of a Binary Tree using a single Stack

   #include using namespace std;    struct Node {     int data;     struct Node *left, *right;        Node(int data)     {         this->data = data;         left = right = NULL;     } };    void allTraversal(Node* root) {          vector pre;             vector post;             vector in;                  stack s;                  s.push(make_pair(root, 1)); […]

Continue Reading