Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Q2. Implementation of a Class Template A stack is an abstract data type that serves as a collection of elements, with two principal operations: push,

Q2. Implementation of a Class Template A stack is an abstract data type that serves as a collection of elements, with two principal operations: push, which adds an element to the collection, and pop, which removes the most recently added element that was not yet removed.

A simple class definition of Stack Class is following:

Rewrite this class definition, so that it will be class template (And so that your new Stack will be able to store various data types.) Implement the default constructor and the functions push, pop to complete the definition of your Stack class template. Test your class by writing a program. Check that whether your Stack is working properly for various data types or not. EXAMPLE: An integer stack example

image text in transcribedimage text in transcribedimage text in transcribed

Q2. Implementation of a Class Template A stack is an abstract data type that serves as a collection of elements, with two principal operations: push, which adds an element to the collection, and pop, which removes the most recently added element that was not yet removed. Department of Computer Engineering - Istanbul Kultur University A simple class definition of Stack Class is following: class Stack { int size; int size; int top; char* stackPtr; public: Stack(int=10); bool push(const char&);// Adds a element at the top of the stack char pop(char&);// Deletes the top most element of the stack bool isEmpty() const { return top == -1; } bool is Full() const { return top == size 1; } }; - Rewrite this class definition, so that it will be class template (And so that your new Stack will be able to store various data types.) Implement the default constructor and the functions push, pop to complete the definition of your Stack class template. Test your class by writing a program. Check that whether your Stack is working properly for various data types or not. Test your class by writing a program. Check that whether your Stack is working properly for various data types or not. EXAMPLE: An integer stack example top 1 ... top- 7 7 5 5 top 5 2 top- 2 2 2 push(2) push(5) push(7) push(1) top 21 top- 7 7 top + 7 5 5 5 top- 5 2 2 2 2 top 2 1 pop pish(21) 21+popo 7+ pop st pop

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

Introductory Relational Database Design For Business With Microsoft Access

Authors: Jonathan Eckstein, Bonnie R. Schultz

1st Edition

1119329418, 978-1119329411

More Books

Students also viewed these Databases questions

Question

Know how to conduct a position analysis

Answered: 1 week ago