Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with this code I can't get the code to printout in c++ #include #include Stack.h using namespace std; int main() { Stack

I need help with this code I can't get the code to printout in c++

#include #include "Stack.h" using namespace std; int main() { Stack intStack(20); // stack of 20 ints // Use intStack intStack.push(1); intStack.push(2); intStack.push(3); intStack.push(4); cout << "4? " << intStack.peek() << endl; cout << "4? " << intStack.pop() << endl; cout << "3? " << intStack.peek() << endl; cout << "isEmpty 0? " << intStack.isEmpty() << endl; cout << "3 2 1? "; while (!intStack.isEmpty()) { cout << intStack.pop() << " "; } cout << endl; cout << "isEmpty 1? " << intStack.isEmpty() << endl; return 0; }

/** * Stack.h *Third simple class (1) Queue (2) Set (3) Stack (4)PriorityList *Stack is probably the oldest concept of an abstract datatype * " in March 1988 Bauer received the Computer Pioneer Award for the invention of the stack principle" * origin: wikipedia *This example of stack is a container class that will store any type of variable or class *It has only four methods: * push: adds an element following the last filled element * pop: removes the last filled element and returns it * peek: returns the last filled element * isEmpty: returns true if there are no used vectors */ #ifndef STACK_H_ #define STACK_H_ #include #include #include template class Stack { private: std::vector elements; int topIndex; //index of last filled vector index public: // Constructor that resizes vector and sets topIndex to -1 Stack(int const & max) { } // Add element at the end of the stack [topIndex] // increase topIndex void push(T const& element) { } // Reduce topIndex and return the element[topIndex] T pop() { } //Return element[topIndex] T peek() const { } //If topIndex indicates empty, return true, else false bool isEmpty() const { // return true if empty. } }; // endl class declaration and definition #endif /* STACK_H_ */

/*

Student Name, CIS127, Assignment 11.1

4? 4 4? 4 3? 3 isEmpty 0? 0 3 2 1? 3 2 1 isEmpty 1? 1 Press any key to continue . . . */

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

Database In Depth Relational Theory For Practitioners

Authors: C.J. Date

1st Edition

0596100124, 978-0596100124

More Books

Students also viewed these Databases questions

Question

What attracts you about this role?

Answered: 1 week ago

Question

How many states in India?

Answered: 1 week ago

Question

HOW IS MARKETING CHANGING WITH ARTIFITIAL INTELIGENCE

Answered: 1 week ago

Question

1. Why do people tell lies on their CVs?

Answered: 1 week ago