Concept explainers
Explanation of Solution
The following is the complete code for the code segment
//include the required header files
#include <iostream>
#include <stack>
#include <cassert>
using namespace std;
//create a structure
struct node_Type
{
int info;
node_Type *nxt;
};
//definition of a class linkedStackType
class linkedStackType
{
//declare some basic functions of stack
public:
linkedStackType();
void push(int n);
void pop();
int top();
bool isEmptyStack();
void clear_Stack();
private:
node_Type *s_Top;
};
//end of the class
//definition of the function linkedStackType()
linkedStackType::linkedStackType()
{
s_Top = NULL;
}
//definition of the function isEmptyStack
bool linkedStackType::isEmptyStack()
{
return (s_Top == NULL);
}
//definition of the function push()
void linkedStackType::push(int item)
{
node_Type *new_Node = new node_Type;
new_Node->info = item;
new_Node->nxt = s_Top;
s_Top = new_Node;
}
//definition of the function top()
int linkedStackType::top()
{
assert(!isEmptyStack());
return s_Top->info;
}
//definition of the function pop()
void linkedStackType::pop()
{
if(isEmptyStack())
cout<<"Stack is empty" << endl;
else
{
node_Type *current = s_Top;
s_Top = s_Top->nxt;
delete current;
}
}
//definition of the function clear_Stack()
void linkedStackType::clear_Stack()
{
while(s_Top != NULL)
{
node_Type *current = s_Top;
s_Top = s_Top->nxt;
delete current;
}
}
//definition of the main function
int main() {
linkedStackType stack;
long long num;
int temp;
int secretNum = 0;
cin >> num;//837298651020706
num = abs(num);
while (num > 0)
{
stack...
Want to see the full answer?
Check out a sample textbook solutionChapter 18 Solutions
C++ Programming: From Problem Analysis to Program Design
- Explain the concept of design patterns in software development. Provide examples of commonly used design patterns and their applications.arrow_forwardWrite steps needed after finishing PC repair.arrow_forwardExplain the importance of code optimization in software development. Provide techniques for optimizing code.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education