Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a program in C + + to create a stack data structure ( do not use the inbuilt stack class ) using arrays. It
Write a program in C to create a stack data structure do not use the inbuilt stack class using arrays. It should support
Push, Pop and Peek operations.
Todo:
Create a stack using arrays with maximum array size
Hint: Define an empty array of type integer with size
Push integers into the stack.
Hint: Create a class Stack with variable defined to track topmost element of stack top and define a method
push which accepts an integer as an argument and inserts the argument into the array and increments the top by
Print the items in stack.
Hint: Loop through the array till top and print the items.
Pop the item from the stack and print the popped item.
Hint: Add a method pop in Stack class and decrement the variable top.
Peek the stack and print the topmost element of the stack do not remove it
Hint: Return the topmost element of the array without decrementing top.
Print the stack.
Hint: Loop through the array till top and print the items.
CSCI
Coding Guidelines
Start coding by creating a class Stack which has a variable top and an
array of size Add methods to Push, Pop, Peek and Print.
Inside the Push method, check if the top is greater than size of the
array. If yes, it represents Stack Overflow. If not, perform
insertion.
Inside the Pop & Peek method, check if top is less than If yes, it
is Stack Underflow. If not, perform pop & peek, respectively.
Inside Print method, loop through all elements in the array till top and
print them.
In main function, create an object of Stack class and call the required
methods.CSCI
Coding Guidelines
Start coding by creating a class Stack which has a variable top and an
array of size Add methods to Push, Pop, Peek and Print.
Inside the Push method, check if the top is greater than size of the
array. If yes, it represents Stack Overflow. If not, perform
insertion.
Inside the Pop & Peek method, check if top is less than If yes, it
is Stack Underflow. If not, perform pop & peek, respectively.
Inside Print method, loop through all elements in the array till top and
print them.
In main function, create an object of Stack class and call the required
methods.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started