Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

my code Description: In this assignment you will create a stack object that will work with a struct data type called Data. The struct data

image text in transcribed

my codeimage text in transcribedimage text in transcribedimage text in transcribed

Description: In this assignment you will create a stack object that will work with a struct data type called Data. The struct data type contains an int called id and a string called information. The stack class will contain all the attributes and methods to have a complete working and proper stack that will work with the struct Data type. You must implement a stack per the definition of a stack as given in class and the stack introduction assignment. Your stack will be an array (size 10) of pointers to Data structs, not the structs themselves. Algorithms: push: The process for pushing to the stack: o Pass data only an int id and string to the stack. Note that the string is an ADT so it should pass by reference. The prototype for push should be one of the following, whichever notation you prefer to use: bool push(int,const string&); bool push(int, const string*); If there is room in the stack: Test the validity of the data (positive int and non-empty string). Do not proceed if the data is invalid. Dynamically create a struct Data to hold the data. Put the id and string in the struct Data. Increment your stack counter. Push the pointer for the struct onto the stack. Return true (or false if the data was invalid). o If there is not room in the stack return false. pop: The process for popping from the stack. o Pass an empty struct Data to the stack (by reference) o If the stack is not empty... Get the data from the top of the stack. Delete the allocated memory from the top of the stack Decrement your stack counter. "Return" the data to the caller. Note that you will not actually "return" the data but instea you will pass by reference an empty Data struct to the stack, have pop() fill it, and returr true. o If the stack is empty Fill the passed struct with -1 and "" (empty string). Return false. peek: The process for peek() is the same as pop() but do not deallocate or decrement the counter. isEmpty: The process for isEmpty() is to return true or false based on the top being -1 or not. Stack::Stack() - Stack::-Stack() { bool Stack::push(int data, const string* info) if (top

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_2

Step: 3

blur-text-image_3

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

1 2 3 Data Base Techniques

Authors: Dick Andersen

1st Edition

0880223464, 978-0880223461

More Books

Students also viewed these Databases questions