Question

In: Computer Science

Programming Project – Deques, Stacks & Queues General Description: Design and develop array based and linked...

Programming Project – Deques, Stacks & Queues

General Description:

Design and develop array based and linked list-based implementations for the Dequeue ADT. Your implementation must support generic data types using C++ templates. Develop Adapter Files to provide Stack and Queue functionality for the Deques.

Definitions:

You should implement the ADTs precisely as described in the following partial header files.

Deque.h

template

class Deque {

public:

        Deque();                    //constructor

        ~Deque();                 //destructor

        void insertFront(const E& e);

        void insertBack(const E& e);

        const E& eraseFront(); // throw(DequeEmpty);        //note that the use of exceptions is optional

        const E& eraseBack(); // throw(DequeEmpty);        //note that the use of exceptions is optional

        const E& front() const; // throw(DequeEmpty);        //note that the use of exceptions is optional

        const E& back() const; // throw(DequeEmpty);        //note that the use of exceptions is optional

        int size () const;

        bool empty() const;

}

You will also need header files for the Stack and Queue ADT’s for each implementation:

Stack.h

template

class Stack {

public:

        Stack();                      //constructor

                                     ~Stack();                                         //destructor

        void push(const E& e);

        const E& pop(); // throw(StackEmpty);        //note that the use of exceptions is optional

        const E& top() const; // throw(StackEmpty);        //note that the use of exceptions is optional

        int size () const;

        bool empty() const;

}

Queue.h

template

class Queue {

public:

        Queue();                    //constructor

                                     ~Queue();                                      //destructor

        void enqueue(const E& e);

        const E& dequeue(); //throw(QueueEmpty); //note that the use of exceptions is optional

        const E& front() const; //throw(QueueEmpty); //note that the use of exceptions is optional

        int size () const;

        bool empty() const;

}

You will need to write two versions of the Deque.cpp file (one for the array-based implementation, one for the linked list based implementation). Both Stack and Queue must be implemented by use of an Adapter applied to the Deque ADT. As a result, you will need 2 additional C++ files, Stack and Queue. Your Stack and Queue cpp files will be much much smaller though. See pages 220 – 222 of your text for a discussion of this topic along with partially provided code.

Requirements:

Develop a C++ software solution that includes an array based and linked-list based implementation for the Deque ADT. Develop C++ Adapter Classes for both the Stack and Queue ADT’s.

You should also provide formal algorithms for each of the methods of your Deque data structures (2 versions, one each for your array and linked list implementations), an efficiency analysis for each of your algorithms, and all of the necessary .cpp and .h files. Be sure to include expand files so that a new data type for the template can easily be added.

Deliverable:

You should provide two separate zip files, one for the array-based implementation and one for the linked-list based implementation. Each zip file should contain 3 header files (Deque.h, Stack.h, Queue.h), 6 cpp files (Deque.cpp, Stack.cpp, Queue.cpp, DequeExpand.cpp, StackExpand.cpp, and QueueExpand.cpp). In addition, you should include a document that contains formal algorithms for each function you have implemented along with a Big O efficiency analysis of the algorithms. Finally, you should include in your document an overall statement regarding the efficiency of each type of implementation (StackArray, StackList, QueueArray and QueueList).

It is always a good idea to include a readme file as well that includes any instructions for compiling and using your software. Although it is not strictly required, It is also advisable to develop a test file that instantiates and tests your stack and queue implementations.

Note on Exceptions:

Implementing your Deque, Stack and Queue to use Exceptions for indicated operations is optional. If you do it, you will receive extra credit (potentially 10 points).

Grading Criteria:

  • Your code must conform to the standardized header files presented in this document.
  • Your code must work! Obviously it has to compile, but it must also work with test code that will create both versions of the stack and queue and test the public functions.
  • Your code will be evaluated for STYLE (as in whitespace, alignment of code blocks, comments that match the code, and appropriate names of variables.)
  • Your efficiency analysis must be performed for every function for each implementation.
  • Your efficiency analysis must include a summary of the overall efficiency of all implementations.

You can add to the header files, but you can change any function.

Solutions

Expert Solution

#include <bits/stdc++.h>
using namespace std;
  
// structure for a node of deque
struct DQueNode {
int value;
DQueNode* next;
DQueNode* prev;
};
  
// Implementation of deque class
class deque {
private:
  
// pointers to head and tail of deque
DQueNode* head;
DQueNode* tail;
  
public:
// constructor
deque()
{
head = tail = NULL;
}
  
// if list is empty
bool isEmpty()
{
if (head == NULL)
return true;
return false;
}
  
// count the number of nodes in list
int size()
{
// if list is not empty
if (!isEmpty()) {
DQueNode* temp = head;
int len = 0;
while (temp != NULL) {
len++;
temp = temp->next;
}
return len;
}
return 0;
}
  
// insert at the first position
void insert_first(int element)
{
// allocating node of DQueNode type
DQueNode* temp = new DQueNode[sizeof(DQueNode)];
temp->value = element;
  
// if the element is first element
if (head == NULL) {
head = tail = temp;
temp->next = temp->prev = NULL;
}
else {
head->prev = temp;
temp->next = head;
temp->prev = NULL;
head = temp;
}
}
  
// insert at last position of deque
void insert_last(int element)
{
// allocating node of DQueNode type
DQueNode* temp = new DQueNode[sizeof(DQueNode)];
temp->value = element;
  
// if element is the first element
if (head == NULL) {
head = tail = temp;
temp->next = temp->prev = NULL;
}
else {
tail->next = temp;
temp->next = NULL;
temp->prev = tail;
tail = temp;
}
}
  
// remove element at the first position
void remove_first()
{
// if list is not empty
if (!isEmpty()) {
DQueNode* temp = head;
head = head->next;
head->prev = NULL;
free(temp);
return;
}
cout << "List is Empty" << endl;
}
  
// remove element at the last position
void remove_last()
{
// if list is not empty
if (!isEmpty()) {
DQueNode* temp = tail;
tail = tail->prev;
tail->next = NULL;
free(temp);
return;
}
cout << "List is Empty" << endl;
}
  
// displays the elements in deque
void display()
{
// if list is not empty
if (!isEmpty()) {
DQueNode* temp = head;
while (temp != NULL) {
cout << temp->value << " ";
temp = temp->next;
}
cout << endl;
return;
}
cout << "List is Empty" << endl;
}
};
  
// Class to implement stack using Deque
class Stack : public deque {
public:
// push to push element at top of stack
// using insert at last function of deque
void push(int element)
{
insert_last(element);
}
  
// pop to remove element at top of stack
// using remove at last function of deque
void pop()
{
remove_last();
}
};
  
// class to implement queue using deque
class Queue : public deque {
public:
// enqueue to insert element at last
// using insert at last function of deque
void enqueue(int element)
{
insert_last(element);
}
  
// dequeue to remove element from first
// using remove at first function of deque
void dequeue()
{
remove_first();
}
};
  
// Driver Code
int main()
{
// object of Stack
Stack stk;
  
// push 7 and 8 at top of stack
stk.push(7);
stk.push(8);
cout << "Stack: ";
stk.display();
  
// pop an element
stk.pop();
cout << "Stack: ";
stk.display();
  
// object of Queue
Queue que;
  
// insert 12 and 13 in queue
que.enqueue(12);
que.enqueue(13);
cout << "Queue: ";
que.display();
  
// delete an element from queue
que.dequeue();
cout << "Queue: ";
que.display();
  
cout << "Size of Stack is " << stk.size() << endl;
cout << "Size of Queue is " << que.size() << endl;
return 0;
}


Related Solutions

JAVA *** All data structures, including array operations, queues, stacks, linked lists, trees, etc need to...
JAVA *** All data structures, including array operations, queues, stacks, linked lists, trees, etc need to be implemented by you. Write a menu driven program that implements the following Binary Search Tree Operations FIND (item) INSERT (item) DELETE (item) DELETE_TREE (delete all nodes - be careful with the traversal!)
(C++ Programming) Practice with Stacks and Queues (PLEASE FOLLOW ALL DIRECTIONS) ·In “stackfib.cpp”, write a non-recursive...
(C++ Programming) Practice with Stacks and Queues (PLEASE FOLLOW ALL DIRECTIONS) ·In “stackfib.cpp”, write a non-recursive function fib() which: ·Takes a single int parameter n ·Returns the nth Fibonacci number. We will start with fib(0) == fib(1) == 1, then fib(n) = fib(n-1) + fib(n-2) ·To compute this without using recursion, we use a stack to store the numbers we need to compute (1)   Initialize your result to be 0 (2)   Push the parameter n onto the stack (3)   While the stack is...
Please post screenshots of outputs. Also make sure to use stacks and queues. You will design...
Please post screenshots of outputs. Also make sure to use stacks and queues. You will design a program to keep track of a restaurants waitlist using a queue implemented with a linked list. Make sure to read pages 1215-1217 and 1227-1251 1. Create a class named waitList that can store a name and number of guests. Use constructors to automatically initialize the member variables. 2. Add the following operations to your program: a. Return the first person in the queue...
Linked List-Based Queue Sketches In this section you will sketch several linked list-based queues. Hint: Recall...
Linked List-Based Queue Sketches In this section you will sketch several linked list-based queues. Hint: Recall that a proper sketch of a linked list-based queue is just a series of boxes with elements inside. 2, 3, 4 Sketch the linked list-based queue that results from the following operations: Default constructor (create empty) Add(2) Add(3) Add(4) ? Replace this with your sketch Add and Remove Sketch the linked list-based queue that results from the following operations: Default constructor (create empty) Add(2)...
Based on your approved project proposal develop the following sections: Organizational Description - this section will...
Based on your approved project proposal develop the following sections: Organizational Description - this section will provide an overview of the organization. This overview will include a summary of: 1- Potential population characteristics (i.e., majority aboriginal populations, etc.). 2- Potential challenges that you can identify for this organization (i.e., access to services due to geographic location, etc.) in which technology can play a significant role. 3- Description of the technological need(s) that this organization is required to address. 4- Proposal...
Create a Deque class based on the following description of deque (double-ended queues). A dequeue is...
Create a Deque class based on the following description of deque (double-ended queues). A dequeue is a double-ended queue. You can insert items at either end and delete them from either end. Therefore, the deque offers two insert operations and two remove operations: insertLeft() and insertRight() removeLeft() and removeRight(). Deques may also have "peek" methods ( peekLeft() and peekRight() )that let you see the left or right item in the deque without remove the item from the deque. For this...
Programming Project #1 – Day Planner In this project we will develop classes to implement a...
Programming Project #1 – Day Planner In this project we will develop classes to implement a Day Planner program. Be sure to develop the code in a step by step manner, finish phase 1 before moving on to phase 2. Phase 1 The class Appointment is essentially a record; an object built from this class will represent an Appointment in a Day Planner . It will contain 5 fields: month (3 character String), day (int), hour (int), minute (int), and...
C++ Programming Enum - Structure - Array You are asked to develop software for HR department...
C++ Programming Enum - Structure - Array You are asked to develop software for HR department to calculate employee’s weekly salary. The program should contain the following information about a student by declaring a struct: Name (string of characters)        Employee ID (string of characters)        Level (ENGINEER, MANGER, DIRECTOR)        Hourly Rate (floating-point number)        Working Hours (floating-point number)        Weekly Salary (floating-point number) Your program will read an employee data and print the information of employee’s Name, Employee...
TITLE Updating Accounts Using Doubly Linked List TOPICS Doubly Linked List DESCRIPTION General Write a program...
TITLE Updating Accounts Using Doubly Linked List TOPICS Doubly Linked List DESCRIPTION General Write a program that will update bank accounts stored in a master file using updates from a transaction file. The program will maintain accounts using a doubly linked list. The input data will consist of two text files: a master file and a transaction file. See data in Test section below.  The master file will contain only the current account data. For each account, it will contain account...
Let A be an integer array of length n. Design a divide and conquer algorithm (description...
Let A be an integer array of length n. Design a divide and conquer algorithm (description and pseudo code) to find the index of an element of the minimum value in the array. If there are several such elements, your algorithm must return the index of the rightmost element. For instance, if A = {0,2,4,5,2,0,3,10}, then the algorithm should return 5, which is the index of the second 0.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT