C++ Programming: From Problem Analysis to Program Design
C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN: 9781337102087
Author: D. S. Malik
Publisher: Cengage Learning
bartleby

Concept explainers

Expert Solution & Answer
Book Icon
Chapter 18, Problem 8SA

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...

Blurred answer
Students have asked these similar questions
Course : Compilation Techniques
2.exercise c
Need help with python for resumes. Please include screenshots of code if possible

Chapter 18 Solutions

C++ Programming: From Problem Analysis to Program Design

Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education