In this lab, using C++, you will create an abstract data type,
using a doubly-linked circular structure to store the values and
links. You must create it by your own and not use any existing
containers.
You will need a QueueNode. You can use a struct for this, as each
node will not have any associated functions. It will have members
for data, and the next and previous pointers.
Data will be positive integers. There will be no NULL pointers.
Every NEXT pointer will point to a QueueNode as will every PREV
pointer.
You will create a new node when the queue is full. As you take the
data out, you will NOT remove the node. Use a sentinel value of -1
to indicate a node is empty.
You will create a Queue class. It will have the data and function
members described below. The queue is a first in first out
structure. You add to the back and can only look at or take off the
front. You will use a circularly linked structure to implement this
queue. In your class you will only have the QueueNode pointers to
the front and to the back:
QueueNode *front // first item in the queue, where you take the
item off
QueueNode *back // last item in the queue, where you add a new item
to
You will implement these functions with appropriate parameters and
return types in your Queue class:
addBack() // puts on item at the end of the queue or
// if the queue is full, creates a new node to store the item
getFront() // returns the value at the front of the queue
removeFront() // removes the first item in the structure
The removeFront() function only replaces the value in the front
node by inserting the sentinel (-1). The getFront() and
removeFront() functions will return a -1 if the queue is empty when
the function is called. Include appropriate constructors and
destructors. You will NOT have a data member (or variable) for
size.
Remember that this list is circular. So you can only identify the
head and tail of the list by the front and back pointers. When you
remove the front node, you will not delete the node itself, but
replace the value stored in the node with -1 (so this node is empty
now), and move the front pointer pointing to the next node in the
list, which is the new head of the list. How do you determine
whether the list is full? When you try to add to the back of the
list, if the node next to the node the back pointer pointing to is
not stored with value “-1”, then the list is full. You need to
create a new node and add that to the back of the list.
HINT: You should sit down and design the whole program before
touching a keyboard. For the queue, sit down with a pencil and a
piece of paper and study the required pointer manipulations. Figure
out how you will test if the queue is full or empty by just using
the front and back pointers. After you complete the design, you
should develop your code first using pseudocode. Then convert it to
C++.
Testing program
You must also write a driver program that uses your queue to
demonstrate it works correctly.
You will prompt the user with a menu. The options should be:
“a. Enter a value to be added to the queue”,
“b. Display first node (front) value”,
“c. Remove first node (front) value”,
“d. Display the queue contents”,
“x. Exit”
For example, after you display the menu, the user enters “a”. Your
program then reads the integer and put it in the back of the list.
You can have the user type “a 7”, or you have “a <newline>
7”. Also validate the user inputs. You will return an error message
if the user attempts to read or remove a value from an empty
queue.
In this lab, using C++, you will create an abstract data type, using a doubly-linked circular...
C++. Please note the BOLDED ITEMS. You will create a simple linked structure. You will use a simple node that has a pointer to a Node. The data for the Node will be a single data member of type char. You will build a structure where the last node you add will point to the first node created, i.e. it will be a circular linked structure. You will create a program that stores characters provided by the user, stored in...
Using C++, create a doubly linked list data structure that stores strings. At a minimum, you must have a List class that contains the list functionality (including an insert function) and a linkable object ("link node") class. For convenience, you may include the data directly or the data may be external to the link node, connected with a reference. You may use an inner class for the LinkNode and/or include the LinkNode class with the List class file if you...
You are required to write the following functions using this class: class Doubly_linked_list // Use a class Doubly_linked_list to represent an object { public: // constructor initialize the nextPtr Doubly_linked_list() { prevPtr = 0; // point to null at the beginning nextPtr = 0; // point to null at the beginning } // get a number int GetNum() { return number; } // set a number void SetNum(int num) { number = num; } // get the prev pointer Doubly_linked_list ...
Using C++ in Visual Studios Rewrite the code to use a Stack instead of a Queue. You will need to think about the differences in the Stack and Queue. Think about how they operate and how the nodes may differ. Modify the code as necessary. You will need to push to the Stack, pop from the Stack, peek at the Stack. You will need a member functions like in the example code. Your program will need to show that everything...
Programming in C: I am trying to modify this linked list to be doubly linked list. I’m also trying to add a print in reverse function. I’m really struggling with how to change the insert function to doubly link the nodes without effecting the alphabetical sorting mechanism. Example of desired output: Enter your choice: 1 to insert an element into the list. 2 to delete an element from the list. 3 to end. ? 1 Enter a character: a The...
Hello, I have some errors in my C++ code when I try to debug it. I tried to follow the requirements stated below: Code: // Linked.h #ifndef INTLINKEDQUEUE #define INTLINKEDQUEUE #include <iostream> usingnamespace std; class IntLinkedQueue { private: struct Node { int data; Node *next; }; Node *front; // -> first item Node *rear; // -> last item Node *p; // traversal position Node *pp ; // previous position int size; // number of elements in the queue public: IntLinkedQueue();...
C++ ((USE STL verison please)) Implement the queue class as shown above. Use your queue to store the names of 5 students waiting outside Student Services to meet with advisors. You may want to add more data to each node including student ID, Major, etc. Add a member function displayQueue which displays the contents of the queue. Write the main function to test the queue. CLASS: #ifdef queue_h #define queue_h namespace queues { struct queueNode{ char data; queueNode *link; };...
***CODE MUST BE IN C++*** Using the linked list in "basic linked list" which has a STRUCTURE for each node, write FUNCTION which starts at the head and outputs the value for each node until the last node is reached. Note: your function should work with the structure that is in this program. Please do not use the example which is for a class, but this example canbe helkpful. Also note that the function must work no matter how many nodes...
Are based on the following Queue class code segment class QueueFull {/* Empty exception class */}; Class Queue Empty {/* Empty exception class */}; struct Node//Node structure int data;//Holds an integer Node* next;//Pointer to next node in the queue}; Class Queue//Linked node implementation of Queue ADT {Private: Node* front;//Pointer to front node of queue Node* rear;//pointer to last node of queue Public: Queue ()://default constructor initializes queue to be empty -Queue ();//Deallocates all nodes in the queue Void Add (int...
// Java Queue LinkedList Assignment // A queue is implemented using a singly linked list. // the variable: back "points" at the first node in the linked list // new elements ( enqueued) are added at the back // the variable: front "points" at the last node in the linked list. // elements are removed (dequeued) from the front // // Several queue instance methods are provided for you; do not change these // Other instance methods are left for...