Bartleby Related Questions Icon
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
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 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
Check MarkThis question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
bartleby
Step by stepSolved in 3 steps
Knowledge Booster
Background pattern image
Similar questions
- Try in. Omega go.arrow_forwardThe for construction is a loops that iteratively processes a given list. Consequently, it works so long even though there are objects to process. What about this claim: true or false?arrow_forwardIf the elements "A", "B", "C" and "D" are placed in a stack and are removed one at a time, in what order will they be removed?arrow_forward
- Data Structures/Algorithms in Javaarrow_forwardWhen an element is removed from a queue, where is it removed from?arrow_forwardInstruction: To test the Linked List class, create a new Java class with the main method, generate Linked List using Integer and check whether all methods do what they’re supposed to do. A sample Java class with main method is provided below including output generated. If you encounter errors, note them and try to correct the codes. Post the changes in your code, if any. Additional Instruction: Linked List is a part of the Collection framework present in java.util package, however, to be able to check the complexity of Linked List operations, we can recode the data structure based on Java Documentation https://docs.oracle.com/javase/8/docs/api/java/util/LinkedList.html package com.linkedlist; public class linkedListTester { public static void main(String[] args) { ListI<Integer> list = new LinkedList<Integer>(); int n=10; for(int i=0;i<n;i++) { list.addFirst(i); } for(int...arrow_forward
- You will create two programs. The first one will use the data structure Stack and the other program will use the data structure Queue. Keep in mind that you should already know from your video and free textbook that Java uses a LinkedList integration for Queue. Stack Program Create a deck of cards using an array (Array size 15). Each card is an object. So you will have to create a Card class that has a value (1 - 10, Jack, Queen, King, Ace) and suit (clubs, diamonds, heart, spade). You will create a stack and randomly pick a card from the deck to put be pushed onto the stack. You will repeat this 5 times. Then you will take cards off the top of the stack (pop) and reveal the values of the cards in the output. As a challenge, you may have the user guess the value and suit of the card at the bottom of the stack. Queue Program There is a new concert coming to town. This concert is popular and has a long line. The line uses the data structure Queue. The people in the line are objects...arrow_forwardWhich of the following is the one that will most likely not be processed when a queue is terminated? What prompted the decision to remove it from general circulation?arrow_forward
arrow_back_ios
arrow_forward_ios