Computer Science, asked by satarup03, 2 months ago

Write a program to input two stacks and compare their contents.​

Answers

Answered by karunadevigaurav
3

Answer:

First check if the size of given stack1 and stack2 are equal. If the size is not equal, set flag to false and return it. If the size is same, then compare the top elements of both of the given stacks. If the top of both stacks is NOT same, set flag to false and return it otherwise pop top elements of both stacks.

Answered by Swati3101
0

Answer:

The output will be the same.

Explanation:

#include <bits/std c++.h>

using namespace std;

bool is Same Stack(stack<string> stack1, stack<string> stack2)

{

   bool flag = true;

   if (stack1.size() != stack2.size()) {

       flag = false;

       return flag;

}

   while (stack1.empty() == false)

{

       if (stack1.top() == stack2.top())

{

stack1.pop();

stack2.pop();

 }

 else

 {

 flag = false;

 break;

 }

 }

   return flag;

}

int main()

{

   stack<string> stack1;

   stack<string> stack2;

   stack1.push("Geeks");

   stack1.push("4");

   stack1.push("Geeks");

   stack1.push("Welcomes");

   stack1.push("You");

   stack2.push("Geeks");

   stack2.push("4");

   stack2.push("Geeks");

   stack2.push("Welcomes");

   stack2.push("You");

  if (is Same Stack(stack1, stack2))

       cout << "Stacks are Same";

   else

       cout << "Stacks are not Same";

return 0;

}

Learn More:

https://brainly.in/question/44408108

https://brainly.in/question/39778832

Similar questions