EBK STARTING OUT WITH C++
EBK STARTING OUT WITH C++
9th Edition
ISBN: 9780134996066
Author: GADDIS
Publisher: PEARSON CUSTOM PUB.(CONSIGNMENT)
bartleby

Concept explainers

Question
Book Icon
Chapter 19, Problem 2PC
Program Plan Intro

Dynamic Stack Template

Program Plan:

Main.cpp:

  • Include required header files.
  • Inside the “main ()” function,
    • Create an object named “dstack” for stack.
    • Declare a variable named “popElem”.
    • Push 3 elements inside the stack using the function “push ()”.
    • Pop 3 elements from the stack using the function “pop ()”.

DynStack.h:

  • Include required header files.
  • Create a template.
  • Declare a class named “DynStack”. Inside the class
    • Inside the “private” access specifier,
      • Give structure declaration for the stack
        • Create an object for the template
        • Create a stack pointer name “next”.
      • Create a stack pointer name “top”
    • Inside the “public” access specifier,
      • Give a declaration for a constructor.
        • Assign null to the top node.
      • Give function declaration for “push ()”, “pop ()”,and “isEmpty ()”.
  • Give the class template.
  • Give function definition for “push ()”.
    • Assign null to the new node.
    • Dynamically allocate memory for new node
    • Assign “num” to the value of new node.
    • Check if the stack is empty using the function “isEmpty ()”
      • If the condition is true then assign new node as the top and make the next node as null.
      • If the condition is not true then, assign top node to the next of new node and assign new node as the top.
  • Give the class template.
  • Give function definition for “pop ()”.
    • Assign null to the temp node.
    • Check if the stack is empty using the function “is_Empty ()”
      • If the condition is true then print “The stack is empty”.
      • If the condition is not true then,
        • Assign top value to the variable “num”.
        • Link top of next node to temp node.
        • Delete the top most node and make temp as the top node.
  • Give function definition for “isEmpty ()”.
    • Assign Boolean value to the variable
    • Check if the top node is null
      • Assign true to “status”.
    • Return the status

Blurred answer
Students have asked these similar questions
C++ ProgrammingActivity: Linked List Stack and BracketsExplain the flow of the main code not necessarily every line, as long as you explain what the important parts of the code do. The code is already correct, just explain the flow SEE ATTACHED PHOTO FOR THE PROBLEM INSTRUCTIONS int main(int argc, char** argv) {     SLLStack* stack = new SLLStack();     int test;     int length;     string str;     char top;     bool flag = true;     cin >> test;     switch (test) {         case 0:             getline(cin, str);              length = str.length();              for(int i = 0; i < length; i++){                 if(str[i] == '{' || str[i] == '(' || str[i] == '['){                     stack->push(str[i]);                 } else if (str[i] == '}' || str[i] == ')' || str[i] == ']'){                     if(!stack->isEmpty()){                         top = stack->top();                         if(top == '{' && str[i] == '}' || top == '(' && str[i] == ')' ||…
Briefly explain stack abstract data type
Fundamental Data Structures: T1: Stack Implementation In this task, you will implement a stack data structure in Python.Create a Python class named Stack that will have the following methods:__init__(self): Initialize an empty stack.push(self, item): Push an item onto the stack.pop(self): Pop and return the top item from the stack. If the stack is empty, return an appropriate message.peek(self): Return the top item from the stack without removing it. If the stack is empty, return an appropriate message.is_empty(self): Check if the stack is empty and return True or False.size(self): Return the number of elements in the stack.T 2: Using the Stack In this task, you will use the stack you implemented to solve a common problem: checking if a string containing parentheses, brackets, and curly braces is balanced.Write a Python function is_balanced(expression) that takes a string containing parentheses, brackets, and curly braces and returns True if the symbols are balanced and False…
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.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning