Question: Code with comments for each line of code please. Starter code ( searchable _ stack.h ) and main.cpp are provided in the pictures. Starter code
Code with comments for each line of code please. Starter code searchablestack.h and main.cpp are provided in the pictures.
Starter code is given in the form of a template class in header file
searchablestack.hYour searchablestack implementation is to include a search capability to be
implemented in the find method. find takes an object of template type T
and searches the stack for a match to that object using the equality operator
If a match is found, that object is to be moved to the top of the stack while
the remaining objects in the stack maintain their relative positions to each
other. If there is more than one match in the stack, only the matched object
nearest the top of the stack is to be moved. After an object is identified
and moved to the top, find is to return a pointer to the top object. If
no match was found, the stack remains unchanged and find is to return a
null pointer.
The remaining stack functions, pushpoptop and empty are to be
implemented according to their usual stack operations and consistent with
the C STL stack specification.
The starter code includes the following:
Private members stackstackcapacity and stacksize to be used for
maintaining the stack.
Private method resize which handles increasing the capacity of the stack
a dynamic array
A default constructor, which creates an empty stack with a capacity of
objects.
An assignment operator overload, which assigns the value all object of a
given stack to the current stack. Note that the copy constructor must be
implemented for this to work. It is included for completeness and is not
needed for this assignment.
You need to implement the following methods look for the TODO comments in
the starter code:
A copy constructor. This constructor is to initialize a searchablestack
object as a copy of the given like object.
The empty method. This method indicates whether or not the stack is empty.
The find method as described above.
The pop method. This method removed the object at the top of the stack.
The push method. This method add an object to the top of the stack. You
need to check for sufficient capacity for adding an object to the stack. If
there is insufficient capacity, call the resize method given in the starter
code which doubles the capacity of the stack.
The top method. This method returns a reference to the object at the top
of the stack.
All these function are to be implemented with constant time algorithms except
as follows:
find should have, worst case, linear time complexity.
push should have constant time complexity, except when the stack capacity
must be increased in which case is should degrade, worst case, to linear.
Leave the TODO comments in place, so your instructor can easily identify
areas of the source file you are to implement.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
