Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

hello there I have a question,, I want to create a programme to check it is a stack or not in c++ Sample Input Create

hello there

I have a question,, I want to create a programme to check it is a stack or not in c++

Sample Input

Create a file with the following lines and use it as input into your program. Please use at least these as your test cases before submitting your code in Canvas.

4 1 2 1 1 2 1 2 2 6 1 5 1 10 1 12 2 10 2 5 2 12 2 1 8 2 8

Sample Output

stack not stack stack 

and this is my program so far but i got stuck on the middle

#include #include #include #include #include using namespace std;

int main() { string input; int num = 0, op = 0, value = 0; vector numbers;

fstream textfile; textfile.open("testcases.txt");

if (textfile) { cout << "succeed"; getline(cin, input); stringstream(input) >> num; bool stack = true; for (int i = 0; i < num; i++) { getline(cin, input); stringstream(input) >> op >> value; if (op == 1) { numbers.push_back(value); }else if (op == 2) { if (numbers.at(numbers.size() -1) != value) { stack = false; }

}

} }

system("pause"); return 0; }

can someone help me and tell me what is my problems

thanks

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases And Information Systems 1 International Baltic Conference Dbandis 2020 Tallinn Estonia June 19 2020 Proceedings

Authors: Tarmo Robal ,Hele-Mai Haav ,Jaan Penjam ,Raimundas Matulevicius

1st Edition

303057671X, 978-3030576714

More Books

Students also viewed these Databases questions

Question

Describe ERP and how it can create efficiency within a business

Answered: 1 week ago