Part 2: Dynamic Stack In this part, you are going to design a dynamic stack of characters implemented as a linked list. Complete the code below as specified by the comments below. typedef char el_t; class Stack { private: struct StackNode { el_t element; StackNode *next; // letter in the node // Pointer to the next node } ; StackNode *top; // Pointer to the stack top public: // Constructor Stack() { top = nullptr; } // Destructor -Stack () ; // Stack operations void push (el_t); void pop (el t &); void getTop (el_t &) const; void displayAll () const; bool isEmpty() const; } ; // implement the public methods highlighted in bold here int main () { Stack s; el_t c; cout << " initial stack contents" << endl; s.displayAl1(); s.pop (c); s.push('a'); cout << endl << " stack contents after pushing a: << endl; s.displayAl1(); s.push( 'b'); cout << endl << " stack contents after pushing b: s.displayAl1(); << endl; s.push('c'); s.push('d'); s.push('e'); s.push ('f'); s.push ( 'g') ; cout << endl << " stack contents after pushing c-g: " << endl; s.displayAl1(); s.getTop(c); cout << endl << "top elment is " << c < endl; s.pop (c); cout << endl << c << endl; cout << endl << stack contents after popping one element: << endl; s.displayAll(); s.pop (c); cout << endl << " " << c << endl; popped element: " stack contents after popping another element: cout << endl << << endl; s.displayAl1(); s.pop(c); s.pop (c); if (!s.isEmpty()) { s.getTop(c); cout << endl << "top elment is " << c << endl; } s.pop (c); cout << endl << stack contents after popping 3 more elements: << endl; s.displayAl1(); s.pop(c); s.pop(c); s.push('a'); s.push( 'b'); cout << endl << " final stack contents << endl; s.displayAll(); return 0;

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

in c++ language please

Part 2: Dynamic Stack
In this part, you are going to design a dynamic stack of characters implemented as a linked
list. Complete the code below as specified by the comments below.
typedef char el_t;
class Stack {
private:
struct StackNode
{
el_t element;
StackNode *next;
// letter in the node
// Pointer to the next node
} ;
StackNode *top;
// Pointer to the stack top
public:
// Constructor
Stack() {
top = nullptr; }
// Destructor
-Stack () ;
// Stack operations
void push (el_t);
void pop (el t &);
void getTop (el_t &) const;
void displayAll () const;
bool isEmpty() const;
} ;
// implement the public methods highlighted in bold here
int main ()
{
Stack s;
el_t c;
cout << " initial stack contents" << endl;
s.displayAl1();
s.pop (c);
s.push('a');
cout << endl << "
stack contents after pushing a:
<< endl;
s.displayAl1();
s.push( 'b');
cout << endl << " stack contents after pushing b:
s.displayAl1();
<< endl;
Transcribed Image Text:Part 2: Dynamic Stack In this part, you are going to design a dynamic stack of characters implemented as a linked list. Complete the code below as specified by the comments below. typedef char el_t; class Stack { private: struct StackNode { el_t element; StackNode *next; // letter in the node // Pointer to the next node } ; StackNode *top; // Pointer to the stack top public: // Constructor Stack() { top = nullptr; } // Destructor -Stack () ; // Stack operations void push (el_t); void pop (el t &); void getTop (el_t &) const; void displayAll () const; bool isEmpty() const; } ; // implement the public methods highlighted in bold here int main () { Stack s; el_t c; cout << " initial stack contents" << endl; s.displayAl1(); s.pop (c); s.push('a'); cout << endl << " stack contents after pushing a: << endl; s.displayAl1(); s.push( 'b'); cout << endl << " stack contents after pushing b: s.displayAl1(); << endl;
s.push('c');
s.push('d');
s.push('e');
s.push ('f');
s.push ( 'g') ;
cout << endl << "
stack contents after pushing c-g: "
<< endl;
s.displayAl1();
s.getTop(c);
cout << endl << "top elment is "
<< c < endl;
s.pop (c);
cout << endl << c << endl;
cout << endl <<
stack contents after popping one element:
<< endl;
s.displayAll();
s.pop (c);
cout << endl << "
" << c << endl;
popped element:
" stack contents after popping another element:
cout << endl <<
<< endl;
s.displayAl1();
s.pop(c);
s.pop (c);
if (!s.isEmpty())
{
s.getTop(c);
cout << endl << "top elment is " << c << endl;
}
s.pop (c);
cout << endl <<
stack contents after popping 3 more elements:
<< endl;
s.displayAl1();
s.pop(c);
s.pop(c);
s.push('a');
s.push( 'b');
cout << endl << " final stack contents << endl;
s.displayAll();
return 0;
Transcribed Image Text:s.push('c'); s.push('d'); s.push('e'); s.push ('f'); s.push ( 'g') ; cout << endl << " stack contents after pushing c-g: " << endl; s.displayAl1(); s.getTop(c); cout << endl << "top elment is " << c < endl; s.pop (c); cout << endl << c << endl; cout << endl << stack contents after popping one element: << endl; s.displayAll(); s.pop (c); cout << endl << " " << c << endl; popped element: " stack contents after popping another element: cout << endl << << endl; s.displayAl1(); s.pop(c); s.pop (c); if (!s.isEmpty()) { s.getTop(c); cout << endl << "top elment is " << c << endl; } s.pop (c); cout << endl << stack contents after popping 3 more elements: << endl; s.displayAl1(); s.pop(c); s.pop(c); s.push('a'); s.push( 'b'); cout << endl << " final stack contents << endl; s.displayAll(); return 0;
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Function Arguments
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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education