Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

Question

Rewrite the interface file, the implementation file, and the application file
for the Stack class (Program 1, Program 2, and Program 3) without using
the List class object as the data member (for example, you can use an array
as the data member).


Transcribed Image Text:Program 1 The interface file for the Stack class 1 /*** 2 * The interface file for the Stack as that composes an object of the List class 3 4 5 6 7 #ifndef STACK_H #define STACK_H #include "list.h" 8 9 // Stack class definition composing a list object 10 template <class T> 11 class Stack 12 { 13 14 15 16 17 18 19 20 21 22 private: List <T> list; public: }; #endif void push (const T& data); void pop (); T& top() const; int size() const; bool empty () const; ***
[画像:Program 2 Implementation file for the Stack class 1 /**** * The implementation file for the Stack using the definition * * 3 * of member function defined in the list class 4 ********* 5 #ifndef STACK_CPP 2 ************************* 6 #define STACK_CPP 7 #include "stack.h" 8 #include "list.cpp" 9 10 11 template <class T> 12 void Stack <T> :: push (const T& value) 13 { // Definition of the push member function 14 15 } list.insert (0, value); 16 // Definition of the pop member function 17 template <class T> 18 void Stack <T> :: pop () 19 { list.erase (0); 20 21 } 22 // Definition of the top member function 23 template <class T> 24 T& Stack <T> :: top () const 25 { 26 27 } 28 // Definition of the size member function 29 template <class T> list.get(0); 30 int Stack <T> :: size () const 31 { list.size(); 32 33 } 34 // Definition of the empty member function 35 template <class T> 36 bool Stack <T> :: empty () const 37 { 38 39} 40 #endif list.empty(); ********* Application File Program 3 is a simple application file to test the operations defined in the Stack class. Program 3 A simple application to test the Stack class 1 2 3 4 #include "stack.cpp" 5 6 int main() 7{ 8 9 10 11 12 13 14 15 16 17 18 * The application file to test the operations in the Stack ***** 19 20 21 22 23 24 25 26} // Instantiation of a Stack object Stack <string> stack; // Pushing four nodes into the stack stack.push ("Henry"); stack.push ("William"); stack.push ("Tara"); stack.push ("Richard"); // Testing the size of the stack after four push cout << "Stack size: " << stack.size() << endl; // Continuously get the value of the top node and pop it from the stack while (!stack.empty()) { cout << "Node value at the top: " << stack.top () << endl; stack.pop(); } // Recheck the size after all elements are popped out cout << "Stack size: " << stack.size(); return 0;]
expand button
Transcribed Image Text:Program 2 Implementation file for the Stack class 1 /**** * The implementation file for the Stack using the definition * * 3 * of member function defined in the list class 4 ********* 5 #ifndef STACK_CPP 2 ************************* 6 #define STACK_CPP 7 #include "stack.h" 8 #include "list.cpp" 9 10 11 template <class T> 12 void Stack <T> :: push (const T& value) 13 { // Definition of the push member function 14 15 } list.insert (0, value); 16 // Definition of the pop member function 17 template <class T> 18 void Stack <T> :: pop () 19 { list.erase (0); 20 21 } 22 // Definition of the top member function 23 template <class T> 24 T& Stack <T> :: top () const 25 { 26 27 } 28 // Definition of the size member function 29 template <class T> list.get(0); 30 int Stack <T> :: size () const 31 { list.size(); 32 33 } 34 // Definition of the empty member function 35 template <class T> 36 bool Stack <T> :: empty () const 37 { 38 39} 40 #endif list.empty(); ********* Application File Program 3 is a simple application file to test the operations defined in the Stack class. Program 3 A simple application to test the Stack class 1 2 3 4 #include "stack.cpp" 5 6 int main() 7{ 8 9 10 11 12 13 14 15 16 17 18 * The application file to test the operations in the Stack ***** 19 20 21 22 23 24 25 26} // Instantiation of a Stack object Stack <string> stack; // Pushing four nodes into the stack stack.push ("Henry"); stack.push ("William"); stack.push ("Tara"); stack.push ("Richard"); // Testing the size of the stack after four push cout << "Stack size: " << stack.size() << endl; // Continuously get the value of the top node and pop it from the stack while (!stack.empty()) { cout << "Node value at the top: " << stack.top () << endl; stack.pop(); } // Recheck the size after all elements are popped out cout << "Stack size: " << stack.size(); return 0;
Expert Solution
Check Mark
Knowledge Booster
Background pattern image
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
    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