Rewrite the interface file, the implementation file, and the application file for the Queue class (Program 1, Program 2, and Program 3) using an array created in the heap /**************************************************************** 2 * The application to test the Queue class * 3 ****************************************************************/ 4 #include "queue.cpp" 5 6 int main ( ) 7 { 8 // Instantiation of a queue object 9 Queue queue; 10 // Pushing four nodes into the queue 11 queue.push ("Henry"); 12 queue.push ("William"); 13 queue.push ("Tara"); 14 queue.push ("Richard"); 15 // Checking the element at the front and the back of the queue 16 cout << "Checking front and back elements"; 17 cout << "after four push operations:" << endl; 18 cout << "Element at the front: " << queue.front () << endl; 19 cout << "Element at the back: " << queue.back () << endl << endl; Program 2 File queue.cpp (continued) / Popping two elements from the queue 21 queue.pop (); 22 queue.pop (); 23 // Checking the front and the back node after two pop operations 24 cout << "Checking front and back elements"; 25 cout << "after two pop operations:" << endl; 26 cout << "Element at the front: " << queue.front () << endl; 27 cout << "Element at the back: " << queue.back () << endl; 28 return 0; 29 }
Rewrite the interface file, the implementation file, and the application file for the Queue class (Program 1, Program 2, and Program 3) using an array created in the heap /**************************************************************** 2 * The application to test the Queue class * 3 ****************************************************************/ 4 #include "queue.cpp" 5 6 int main ( ) 7 { 8 // Instantiation of a queue object 9 Queue queue; 10 // Pushing four nodes into the queue 11 queue.push ("Henry"); 12 queue.push ("William"); 13 queue.push ("Tara"); 14 queue.push ("Richard"); 15 // Checking the element at the front and the back of the queue 16 cout << "Checking front and back elements"; 17 cout << "after four push operations:" << endl; 18 cout << "Element at the front: " << queue.front () << endl; 19 cout << "Element at the back: " << queue.back () << endl << endl; Program 2 File queue.cpp (continued) / Popping two elements from the queue 21 queue.pop (); 22 queue.pop (); 23 // Checking the front and the back node after two pop operations 24 cout << "Checking front and back elements"; 25 cout << "after two pop operations:" << endl; 26 cout << "Element at the front: " << queue.front () << endl; 27 cout << "Element at the back: " << queue.back () << endl; 28 return 0; 29 }
Related questions
Question
Rewrite the interface file, the implementation file, and the application file
for the Queue class (Program 1, Program 2, and Program 3) using an array
created in the heap
for the Queue class (Program 1, Program 2, and Program 3) using an array
created in the heap
/****************************************************************
2 * The application to test the Queue class *
3 ****************************************************************/
4 #include "queue.cpp"
5
6 int main ( )
7 {
8 // Instantiation of a queue object
9 Queue <string> queue;
10 // Pushing four nodes into the queue
11 queue.push ("Henry");
12 queue.push ("William");
13 queue.push ("Tara");
14 queue.push ("Richard");
15 // Checking the element at the front and the back of the queue
16 cout << "Checking front and back elements";
17 cout << "after four push operations:" << endl;
18 cout << "Element at the front: " << queue.front () << endl;
19 cout << "Element at the back: " << queue.back () << endl << endl;
Program 2 File queue.cpp (continued)
2 * The application to test the Queue class *
3 ****************************************************************/
4 #include "queue.cpp"
5
6 int main ( )
7 {
8 // Instantiation of a queue object
9 Queue <string> queue;
10 // Pushing four nodes into the queue
11 queue.push ("Henry");
12 queue.push ("William");
13 queue.push ("Tara");
14 queue.push ("Richard");
15 // Checking the element at the front and the back of the queue
16 cout << "Checking front and back elements";
17 cout << "after four push operations:" << endl;
18 cout << "Element at the front: " << queue.front () << endl;
19 cout << "Element at the back: " << queue.back () << endl << endl;
Program 2 File queue.cpp (continued)
/ Popping two elements from the queue
21 queue.pop ();
22 queue.pop ();
23 // Checking the front and the back node after two pop operations
24 cout << "Checking front and back elements";
25 cout << "after two pop operations:" << endl;
26 cout << "Element at the front: " << queue.front () << endl;
27 cout << "Element at the back: " << queue.back () << endl;
28 return 0;
29 }
21 queue.pop ();
22 queue.pop ();
23 // Checking the front and the back node after two pop operations
24 cout << "Checking front and back elements";
25 cout << "after two pop operations:" << endl;
26 cout << "Element at the front: " << queue.front () << endl;
27 cout << "Element at the back: " << queue.back () << endl;
28 return 0;
29 }

Transcribed Image Text:Interface File
Program 1 shows the interface file. Note that we include the interface file of our List
class.
Program 1 File queue.h
1
2
3
4
5
#ifndef QUEUE_H
6 #define QUEUE_H
7
#include "list.h"
8
9 template <class T>
10 class Queue
11 {
12
* The interface file to define a Queue class using a List
* object as the only data member
13
14
15
16
17
18
19
20
private:
List <T> list;
public:
void push (const T& data);
void pop ();
T& front() const;
T& back() const;
int size() const;
bool empty () const;
Program 1 File queue.h (continued)
21 };
22 #endif
3

Transcribed Image Text:Program File queue.cpp
1
2
3
The implementation for the Queue class in terms of operations*
* defined for the List class
4
5 #ifndef QUEUE_CPP
*******
6
#define QUEUE_CPP
7 #include "queue.h"
8
#include "list.cpp"
9
10
11 template <class T>
// Definition of push operation
12 void Queue <T> :: push (const T& value)
13 {
14
15}
16 // Definition of pop operation
17 template <class T>
18 void Queue <T> :: pop ()
19 {
list.insert (list.size (), value);
20
21 }
22 // Definition of front operation
23 template <class T>
list.erase (0);
24 T& Queue <T> :: front () const
25 {
26
27 }
28 // Definition of back operation
29 template <class T>
list.get(0);
Program 2 File queue.cpp (continued)
30 T& Queue <T> :: back () const
31 {
32
list.get (list.size () - 1);
33 }
34 // Definition of size operation
35 template <class T>
36 int Queue <T> :: size () const
37 {
38
list.size ();
#endif
39}
40 // Definition of empty operation
41 template <class T>
42 bool Queue <T> :: empty () const
43 {
44
45 }
46
list.empty();
*
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 3 steps with 3 images
