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 C++ programs to implement Queue ADT data structure using Linked List.
Write C++ programs to implement Queue ADT data structure using 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.
IN JAVA LANGUAGE Linked List-Based Queue Implementation Implement Queue using a Linked List. Use the language...
IN JAVA LANGUAGE Linked List-Based Queue Implementation Implement Queue using a Linked List. Use the language library LinkedList Queue methods will call the LinkedList methods You can use string as the object Instead of using an array, as the QueueLab did, here you will use a Linked List from your language's library. Implement all the methods of Stack : enqueue(), dequeue(), size(), printQueue(), etc, using calls to the linked list methods that correspond to the actions need. In the array...
Give a complete implementation of the queue ADT using a singly linked list that includes a...
Give a complete implementation of the queue ADT using a singly linked list that includes a header sentinel (in Python).
Implement the ADT character string as the class LinkedString by using a linked list of characters....
Implement the ADT character string as the class LinkedString by using a linked list of characters. Include the following LinkedString constructors and methods: LinkedString(char[] value) Allocates a new character linked list so that it represents the sequence of characters currently contained in the character array argument. LinkedString(String original) Initializes a new character linked list so that it represents the same sequence of characters as the argument. char charAt(int index) Returns the char value at the specified index. The first character...
Show how circular linked list can be useful to implement Circular Queue (CQ) ADT (Abstract Data...
Show how circular linked list can be useful to implement Circular Queue (CQ) ADT (Abstract Data Type). Compare and contrast with array based implementation. Which one would you recommend to implement CQ and why
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)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT