file for the Queue class (Program 1, Program 2, and Program 3) without using
file for the Queue class (Program 1, Program 2, and Program 3) without using
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) without using
the List class object as the data member
add results in the end of the program
![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](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fd5246d2a-5796-4784-a543-e596d3b5542c%2F29a00c87-e104-430e-bb6c-d76ed93bac4a%2Fh43929_processed.png&w=3840&q=75)
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
![Program 3 Application file to test Queue class
2
3
4 #include "queue.cpp"
5
6
7
8
9
10
11
12
13
14
15
16
* The application to test the Queue class
17
18
19
int main ()
}{
Program 3 Application file to test Queue class (continued)
// Popping two elements from the queue
queue.pop();
queue.pop();
// Checking the front and the back node after two pop operations
cout << "Checking front and back elements";
20
21
22
23
24
25
26
// Instantiation of a queue object
Queue <string> queue;
// Pushing four nodes into the queue
queue.push ("Henry");
queue.push ("William");
queue.push ("Tara");
queue.push ("Richard");
// Checking the element at the front and the back of the queue
cout << "Checking front and back elements";
cout << "after four push operations:" << endl;
cout << "Element at the front: " << queue.front () << endl;
cout << "Element at the back: " << queue.back () << endl << endl;
27
28
29
cout << "after two pop operations:" << endl;
cout << "Element at the front: " << queue.front () << endl;
cout << "Element at the back: " << queue.back () << endl;
return 0;
Program
1
2
3
20
21
Press Est to exit four screen
File queue.cpp
5 #ifndef QUEUE_CPP
6 #define QUEUE_CPP
7 #include "queue.h"
8 #include "list.cpp"
9
10
11 template <class T>
12 void Queue <T> :: push (const T& value)
13 {
14
15)
The implementation for the Queue class in terms of operations*
defined for the List class.
// Definition of push operation
list.insert (list.size (), value);
16
17 template <class T>
18 void Queue <T> :: pop ()
19 {
Definition of pop operation
list.erase (0);
22 // Definition of front operation
23 template <class T>
24 T& Queue <T> :: front () const
25 {
26
27
28 // Definition of back operation
29 template <class T>
43 {
44
45}
46 #endif
list.get(0);
Program 2 File queue.cpp (continued)
30 T& Queue <T> :: back () const
31 {
32
33 }
34
// Definition of size operation
35
template <class T>
36 int Queue <T> :: size () const
{
list.get (list.size() - 1);
37
38
39}
40 // Definition of empty operation
41 template <class T>
42 bool Queue <T> :: empty () const
list.size();
5
list.empty();
*](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fd5246d2a-5796-4784-a543-e596d3b5542c%2F29a00c87-e104-430e-bb6c-d76ed93bac4a%2Ftbx20gq_processed.png&w=3840&q=75)
Transcribed Image Text:Program 3 Application file to test Queue class
2
3
4 #include "queue.cpp"
5
6
7
8
9
10
11
12
13
14
15
16
* The application to test the Queue class
17
18
19
int main ()
}{
Program 3 Application file to test Queue class (continued)
// Popping two elements from the queue
queue.pop();
queue.pop();
// Checking the front and the back node after two pop operations
cout << "Checking front and back elements";
20
21
22
23
24
25
26
// Instantiation of a queue object
Queue <string> queue;
// Pushing four nodes into the queue
queue.push ("Henry");
queue.push ("William");
queue.push ("Tara");
queue.push ("Richard");
// Checking the element at the front and the back of the queue
cout << "Checking front and back elements";
cout << "after four push operations:" << endl;
cout << "Element at the front: " << queue.front () << endl;
cout << "Element at the back: " << queue.back () << endl << endl;
27
28
29
cout << "after two pop operations:" << endl;
cout << "Element at the front: " << queue.front () << endl;
cout << "Element at the back: " << queue.back () << endl;
return 0;
Program
1
2
3
20
21
Press Est to exit four screen
File queue.cpp
5 #ifndef QUEUE_CPP
6 #define QUEUE_CPP
7 #include "queue.h"
8 #include "list.cpp"
9
10
11 template <class T>
12 void Queue <T> :: push (const T& value)
13 {
14
15)
The implementation for the Queue class in terms of operations*
defined for the List class.
// Definition of push operation
list.insert (list.size (), value);
16
17 template <class T>
18 void Queue <T> :: pop ()
19 {
Definition of pop operation
list.erase (0);
22 // Definition of front operation
23 template <class T>
24 T& Queue <T> :: front () const
25 {
26
27
28 // Definition of back operation
29 template <class T>
43 {
44
45}
46 #endif
list.get(0);
Program 2 File queue.cpp (continued)
30 T& Queue <T> :: back () const
31 {
32
33 }
34
// Definition of size operation
35
template <class T>
36 int Queue <T> :: size () const
{
list.get (list.size() - 1);
37
38
39}
40 // Definition of empty operation
41 template <class T>
42 bool Queue <T> :: empty () const
list.size();
5
list.empty();
*
Expert Solution
![](/static/compass_v2/shared-icons/check-mark.png)
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
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)