Question: 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



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
Get step-by-step solutions from verified subject matter experts
