Question

In: Computer Science

Write a template class that implements an extended queue (use singly Linked List) in c++ please...

Write a template class that implements an extended queue (use singly Linked List) in c++

please create 3 classes

please create 3 classes

please create 3 classes

please create 3 classes

please create 3 classes

Ex:

ExtendedQueue int_queue;

ExtendedQueue double_queue;

ExtendedQueue char_queue;

–Write a program to test this template class.

you have to use inheritance

so you will create 3 classes :

so you will create 3 classes :

so you will create 3 classes :

so you will create 3 classes :

so you will create 3 classes :

so you will create 3 classes :

one for node

one for queue

one for extended queue inherited for queue .

the details of the ExtendedQueue:
insert
delete
front
rear
queue size.
the output will be:
Inserting 2
Inserting 4
Inserting 6
Front element is: 2
Removing 2
Inserting 8
Queue size is 3
Removing 4
Removing 6
Removing 8
Queue Is Empty

Solutions

Expert Solution

//========ExtendedQueue.h=====
template <class T>
class ExtendedQueue{
private:
//node definition
class Node{
public:
T data;
Node *link;
Node(){
link=NULL;
}
Node(T item){
data=item;
link=NULL;
}
};
//node definition ends
Node *FRONT,*REAR;
int total;
public:
ExtendedQueue();
~ExtendedQueue();
void insertQueue(T item);
T deleteQueue();
T front();
T rear();
int size();
void printQueue();
};
//_____constructor_________________
template <class T>
ExtendedQueue <T>:: ExtendedQueue(){
FRONT=REAR=NULL;
total=0;
}
//______destructor________________
template <class T>
ExtendedQueue <T>:: ~ExtendedQueue(){
Node*temp;
while(REAR){
temp=REAR->link;
delete REAR;
REAR=temp;
}
}
//______size of queue________________
template <class T>
int ExtendedQueue<T> :: size(){
return total;
}
//_______front_______________
template <class T>
T ExtendedQueue<T> :: front(){
if(FRONT==NULL){
cout<<"Queue is Empty."<<endl;
return 0;
}
return FRONT->data;
}
//______rear________________
template <class T>
T ExtendedQueue<T> :: rear(){
if(REAR==NULL){
cout<<"Queue is Empty."<<endl;
return 0;
}
return REAR->data;
}
//_______insertQueue_______________
template <class T>
void ExtendedQueue<T> :: insertQueue(T item){
Node *p=new Node(item);
if(!p){
cout<<"\nMemory is not available"<<endl;
return;
}

if(FRONT==NULL)
FRONT=REAR=p;
else{
FRONT->link=p;
FRONT=p;
}
total++;
cout<<"Inserting "<<item<<endl;

}
//_______deleteQueue_______________
template <class T>
T ExtendedQueue <T>:: deleteQueue()
{
if(REAR==NULL){
cout<<"Queue is Empty."<<endl;
return 0;
}

T item=REAR->data;
if(FRONT == REAR)
FRONT=REAR=NULL;
else
REAR=REAR->link;
total--;
cout<<"Removing "<<item<<endl;

return item;

}

|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

TestMain.cpp

|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

#include<iostream>
using namespace std;
#include "ExtendedQueue.h"

int main(){
ExtendedQueue<int> Q;
Q.insertQueue(2);
Q.insertQueue(4);
Q.insertQueue(6);
cout<<"Front element is: "<<Q.front()<<endl;
Q.deleteQueue();
Q.insertQueue(8);
cout<<"Queue size is: "<<Q.size()<<endl;
Q.deleteQueue();
Q.deleteQueue();
Q.deleteQueue();
Q.deleteQueue();
return 0;
}

SCREENSHOT OF PROGRAM AND OUTPUT RAN ON DEV++


Related Solutions

please answer my question... Write a template class that implements an extended queue (use Linked List)....
please answer my question... Write a template class that implements an extended queue (use Linked List). Ex: ExtendedQueue<int> int_queue; ExtendedQueue<double> double_queue; ExtendedQueue<char> char_queue; –Write a program to test this template class in c++. the details of the ExtendedQueue: insert delete front rear queue size. the output will be: Inserting 2 Inserting 4 Inserting 6 Front element is: 2 Removing 2 Inserting 8 Queue size is 3 Removing 4 Removing 6 Removing 8 Queue Is Empty
In C++, Implement the queue ADT with a singly linked list
In C++, Implement the queue ADT with a singly linked list
Using the singly linked list code as a base, create a class that implements a doubly...
Using the singly linked list code as a base, create a class that implements a doubly linked list. A doubly linked list has a Previous link so you can move backwards in the list. Be sure the class is a template class so the user can create a list with any data type. Be sure to test all the member functions in your test program. c++
I've provided a Node class that implements a node of a simple singly-linked list (with .value...
I've provided a Node class that implements a node of a simple singly-linked list (with .value and .next fields), and an empty LinkedList class. Your task is to implement LinkedList.sort(l), where given the node l as the head of a singly-linked list, LinkedList.sort(l) sorts the nodes in the list into ascending order according to the values in the .value field of each node. Your implementation should do an in-place update of the list. It is ok to use a simple...
Objectives: Define the new class type: Queue using a singly linked list. Define the new class...
Objectives: Define the new class type: Queue using a singly linked list. Define the new class type: Jukebox which creates three objects of type Queue class. Practice enqueue-ing and dequeue-ing elements from the top of your singly linked list Queue class. Test the implementation of the class: MyTunes. The class files are here: https://drive.google.com/file/d/1yCCQeZCS-uLoL_CK0Et9dX-KCaokXQxR/view?usp=sharing class MyTunes Creates an object of type MyTunes class that partially simulate the digital jukebox TouchTunes, using a queue which holds playlist. Tests the implementation of...
Solve this Write a C++ class that implements a stack using a linked list. The type...
Solve this Write a C++ class that implements a stack using a linked list. The type of data contained in the stack should be double. The maximum size of the stack is 30. Implement the following methods: . · Constructor and destructor; // 5 pts · void push (double value); // pushes an element with the value into the stack. 5 pts. · double pop (); // pops an element from the stack and returns its value. 5 pts. ·...
Write a code to implement a python queue class using a linked list. use these operations...
Write a code to implement a python queue class using a linked list. use these operations isEmpty • enqueue. • dequeue    • size Time and compare the performances of the operations ( this is optional but I would appreciate it)
c. You are given the following Java files: SLL.java that implements generic Singly Linked List, with...
c. You are given the following Java files: SLL.java that implements generic Singly Linked List, with class SLLNode listed as inner class. TestIntegerSLL.java that tests the SLL class by using a linked list of Integer. In SLL class add the following method:                                                                    public void moveToEnd (int i) It will move the element at the i -th position to the end of the list. You can assume i to be within the list, and that the first element has the...
Exercise 1: Write a program in Java to manipulate a Singly Linked List: 1. Create Singly...
Exercise 1: Write a program in Java to manipulate a Singly Linked List: 1. Create Singly Linked List 2. Display the list 3. Count the number of nodes 4. Insert a new node at the beginning of a Singly Linked List. 5. Insert a new node at the end of a Singly Linked List 6. Insert a new node after the value 5 of Singly Linked List 7. Delete the node with value 6. 8. Search an existing element in...
Please use C++ and linked list to solve this problem Linked list 1 -> 3 ->...
Please use C++ and linked list to solve this problem Linked list 1 -> 3 -> 4 -> 5-> 6 ->7 replaceNode( 5 , 6) // Replace 5 with 6     result 1 -> 3 -> 4 -> 6 -> 6 ->7 Base code #include <iostream> using namespace std; class Node { public:     int data;     Node *next;     Node(int da = 0, Node *p = NULL) {         this->data = da;         this->next = p;     } };...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT