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.
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...
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...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT