Question

In: Computer Science

implement the Queue ADT using the linked list approach #include "QueueLinked.h" template QueueLinked::QueueNode::QueueNode(const DataType& nodeData, QueueNode*...

implement the Queue ADT using the linked list approach

#include "QueueLinked.h"

template
QueueLinked::QueueNode::QueueNode(const DataType& nodeData, QueueNode* nextPtr)
{
}

template
QueueLinked::QueueLinked(int maxNumber = Queue::MAX_QUEUE_SIZE)
{
}

template
QueueLinked::QueueLinked(const QueueLinked& other)
{
}

template
QueueLinked& QueueLinked::operator=(const QueueLinked& other)
{
}

template
QueueLinked::~QueueLinked()
{
}

template
void QueueLinked::enqueue(const DataType& newDataItem) throw (logic_error)
{
}

template
DataType QueueLinked::dequeue() throw (logic_error)
{
   DataType temp;
   return temp;
}

template
void QueueLinked::clear()
{
}

template
bool QueueLinked::isEmpty() const
{
   return false;
}

template
bool QueueLinked::isFull() const
{
   return false;
}

template
void QueueLinked::putFront(const DataType& newDataItem) throw (logic_error)
{
}

template
DataType QueueLinked::getRear() throw (logic_error)
{
   DataType temp;
   return temp;
}

template
int QueueLinked::getLength() const
{
}

template
void QueueLinked::showStructure() const
{
QueueNode *p; // Iterates through the queue

if ( isEmpty() )
   cout << "Empty queue" << endl;
else
{
   cout << "Front\t";
   for ( p = front ; p != 0 ; p = p->next )
   {
   if( p == front )
   {
       cout << '[' << p->dataItem << "] ";
   }
   else
   {
       cout << p->dataItem << " ";
   }
   }
   cout << "\trear" << endl;
}
}

-----------------------------------------------------------------------------------------------------------------------------------------------------------

// QueueLinked.h

#include
#include

using namespace std;

#include "Queue.h"

template
class QueueLinked : public Queue {
public:
QueueLinked(int maxNumber = Queue::MAX_QUEUE_SIZE);
QueueLinked(const QueueLinked& other);
QueueLinked& operator=(const QueueLinked& other);
~QueueLinked();

void enqueue(const DataType& newDataItem) throw (logic_error);
DataType dequeue() throw (logic_error);

void clear();

bool isEmpty() const;
bool isFull() const;

// Programming Exercise 2
void putFront(const DataType& newDataItem) throw (logic_error);
DataType getRear() throw (logic_error);
// Programming Exercise 3
int getLength() const;

void showStructure() const;

private:
class QueueNode {
public:
   QueueNode(const DataType& nodeData, QueueNode* nextPtr);

   DataType dataItem;
   QueueNode* next;
};

QueueNode* front;
QueueNode* back;
};

---------------------------------------------------------------------------------------------------

// QueueLinked.h

#include <stdexcept>
#include <iostream>

using namespace std;

#include "Queue.h"

template <typename DataType>
class QueueLinked : public Queue<DataType> {
public:
QueueLinked(int maxNumber = Queue<DataType>::MAX_QUEUE_SIZE);
QueueLinked(const QueueLinked& other);
QueueLinked& operator=(const QueueLinked& other);
~QueueLinked();

void enqueue(const DataType& newDataItem) throw (logic_error);
DataType dequeue() throw (logic_error);

void clear();

bool isEmpty() const;
bool isFull() const;

// Programming Exercise 2
void putFront(const DataType& newDataItem) throw (logic_error);
DataType getRear() throw (logic_error);
// Programming Exercise 3
int getLength() const;

void showStructure() const;

private:
class QueueNode {
public:
   QueueNode(const DataType& nodeData, QueueNode* nextPtr);

   DataType dataItem;
   QueueNode* next;
};

QueueNode* front;
QueueNode* back;
};

Solutions

Expert Solution

#include
#include

using namespace std;

#include "Queue.h"

template
class QueueLinked : public Queue {
public:
QueueLinked(int maxNumber = Queue::MAX_QUEUE_SIZE);
QueueLinked(const QueueLinked& other);
QueueLinked& operator=(const QueueLinked& other);
~QueueLinked();

void enqueue(const DataType& newDataItem) throw (logic_error);
DataType dequeue() throw (logic_error);

void clear();

bool isEmpty() const;
bool isFull() const;

// Programming Exercise 2
void putFront(const DataType& newDataItem) throw (logic_error);
DataType getRear() throw (logic_error);
// Programming Exercise 3
int getLength() const;

void showStructure() const;

private:
class QueueNode {
public:
   QueueNode(const DataType& nodeData, QueueNode* nextPtr);

   DataType dataItem;
   QueueNode* next;
};

QueueNode* front;
QueueNode* back;
};

---------------------------------------------------------------------------------------------------

// QueueLinked.h

#include <stdexcept>
#include <iostream>

using namespace std;

#include "Queue.h"

template <typename DataType>
class QueueLinked : public Queue<DataType> {
public:
QueueLinked(int maxNumber = Queue<DataType>::MAX_QUEUE_SIZE);
QueueLinked(const QueueLinked& other);
QueueLinked& operator=(const QueueLinked& other);
~QueueLinked();

void enqueue(const DataType& newDataItem) throw (logic_error);
DataType dequeue() throw (logic_error);

void clear();

bool isEmpty() const;
bool isFull() const;

// Programming Exercise 2
void putFront(const DataType& newDataItem) throw (logic_error);
DataType getRear() throw (logic_error);
// Programming Exercise 3
int getLength() const;

void showStructure() const;

private:
class QueueNode {
public:
   QueueNode(const DataType& nodeData, QueueNode* nextPtr);

   DataType dataItem;
   QueueNode* next;
};

QueueNode* front;
QueueNode* back;
};


Related Solutions

In C++, Implement the queue ADT with a singly linked list
In C++, Implement the queue ADT with a singly linked list
write a java program to Implement a Priority Queue using a linked list. Include a main...
write a java program to Implement a Priority Queue using a linked list. Include a main method demonstrating enqueuing and dequeuing several numbers, printing the list contents for each.
Using the linked list abstract data type “Queue ADT”, write a menu dirven user interfece to...
Using the linked list abstract data type “Queue ADT”, write a menu dirven user interfece to teach each of the operations in the ADT. Any errors discovered during the processing should be printed as a part of the test result. Please Use C++ language.
C++ Data Structures: Implement a Stack and a Queue using Linked list In this lab you...
C++ Data Structures: Implement a Stack and a Queue using Linked list In this lab you will implement the functionality of a stack and a queue using a linked list. Your program must use of the declaration of the Stack and Queue class in Stack.h and Queue.h You have to implement the functionalities of queue (enq, deq, displayQueue) in a file called Queue.cpp. All the functions in Queue.cpp should follow the prototypes declared in Queue.h. Your code should make use...
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)
1. Implement the graph ADT using the adjacency list structure. 2. Implement the graph ADT using...
1. Implement the graph ADT using the adjacency list structure. 2. Implement the graph ADT using the adjacency matrix structure. LANGUAGE IS IN JAVA Comment for any questions Data structures and algorithms
26.5 Project 3: List & Queue ADT Overview For this project, you are to implement two...
26.5 Project 3: List & Queue ADT Overview For this project, you are to implement two abstract data types (ADTs). You will write a doubly linked list (Dll) and a queue class. The queue will use the dll internally. The class interfaces are downloadable below. You must follow the interface exactly. While you can define other public and private methods and fields, the class names and methods given must appear as provided, or you will not pass the unit tests....
Using a single queue (linkedQueue), re-implement the concept of Stack ADT, what is the complexity of...
Using a single queue (linkedQueue), re-implement the concept of Stack ADT, what is the complexity of the method push, pop, top, isEmpty, and size. You should not use any extra data structure. Related codes: public interface Stack<E> { int size( ); boolean isEmpty( ); void push(E e); E top( ); E pop( ); } public class LinkedStack<E> implements Stack<E> { private SinglyLinkedList<E> list = new SinglyLinkedList<>( );    public LinkedStack( ) { }    public int size( ) { return...
please complete the header file that contains a class template for ADT Queue and complete all...
please complete the header file that contains a class template for ADT Queue and complete all the member functions in the class template. Submit the header file only, but please write a source file that tests all the member functions to make sure they are working correctly. queue.h #ifndef _QUEUE #define _QUEUE #include"Node.h" template<class ItemType> class Queue { private:    Node<ItemType> *backPtr;    Node<ItemType> *frontPtr; public:    Queue(); //Default constructor    Queue(const Queue<ItemType> &aQueue);    bool isEmpty() const;    bool...
by java Implement a linked list generic queue. Remember queues are first in first out (FIFO)....
by java Implement a linked list generic queue. Remember queues are first in first out (FIFO). Use the driver to then test each of the methods. Simply download it and place it with the other source files. Create a class GenLLQueue which has the following: Internal class ListNode which contains: Instance variable data of type T Instance variable link of type ListNode Default constructor that sets both instance variables to null Instance Variables head which is of type ListNode which...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT