PROBLEM:
string CBQueue::dequeue( )
This method should remove and return the item at the front of the queue- please add comments
EXISTING CODE:
#include // this allows you to declare and use strings
#include
using namespace std;
struct qNode
{
string data;
qNode* next;
qNode* prev;
};
class CBQueue
{
public:
CBQueue();
int CBQueue::getSize( );
bool CBQueue::isEmpty( );
private:
qNode* front;
qNode* rear;
int size;
};
#include "CBQueue.h"
CBQueue::CBQueue()
{
front = NULL;
rear = NULL;
size = 0;
}
//Returns elements in CBQuene
int CBQueue::getSize( ){
return size;
}
//return whether the queue is empty or not
bool CBQueue::isEmpty( ){
if(front == NULL)}{
return true;
}
else{
return false;
}
//
void CBQueue::enqueue(string s){
//Create a structure of Node which will hold the data s
struct qNode * temp = (struct qNode *)malloc(sizeof(struct qNode));
//data assigned as s
temp->data = s;
//initially prevIOUS pointer is NULL
temp->prev = NULL;
//initially next pointer is NULL
temp->next = NULL;
//If it is the first NODE
if (front == NULL)
{
//THEN FRONT AS REAR IS ASSIGNED AS TEMP
front = rear = temp;
}
else
{
//Otherwise add the new node to the rear end
rear->next = temp;
//Make temp previous as rear
temp->prev = rear;
//Now the temp becomes the rear
rear = temp;
}
//
void CBQuelue::printF2B( ){
temp = front;
//check if quene is empty
if ((front == NULL) && (rear == NULL)) {
cout<<"Queue is empty."<
return;
}
//if not empty-then print the items of the quene starting at the front and proceed to the rear
cout<<"Queue elements are (Front to Rear): ";
while (temp != NULL) { //while(temp)?
cout
temp = temp->next;
}
cout<
}
string CBQueue::dequeue( ){
}
string CBQueue::dequeue( ){
// if the queue is empty
if( this->front == NULL )
return "";
// if the queue is not empty
else
{
// store the front element in the beginning of the queue
string x = this->front->data;
// make second node as the new front node
this->front = this->front->next;
// delete the previous front node
delete this->front->prev;
this->front->prev = NULL;
return x;
}
}
PROBLEM: string CBQueue::dequeue( ) This method should remove and return the item at the front of...
PROBLEM- void CBQueue::printF2B( ) If the queue is empty, the method should print “Queue is empty”, otherwise, this method should print the items in the queue starting at the front of the queue and proceeding to the rear of the queue. The items should be printed one per line. Now that this method is written, you can do a more thorough job of testing enqueue( ). You will want to call printF2B( ) and printB2F( ) after implementing each method...
Help me solve this in C++ Rewrite the code to use array instead of linked lists. Please do not change anything besides the data structure. Instead of linked list use an array. The functionality should remain exactly the same. You can prepare a class if you wish but it is not required. /** * Queue implementation using linked list C style implementation ( no OOP). */ #include <cstdio> #include <cstdlib> #include <climits> #include <iostream> #define CAPACITY 100 // Queue max...
How do I pass values to this function? class DynIntQueue { struct QueueNode { int value; QueueNode *next; QueueNode(int value1, QueueNode *next1 = nullptr) { value = value1; next = next1; } }; // These track the front and rear of the queue QueueNode *front; QueueNode *rear; public: // Constructor and Destructor DynIntQueue(); ~DynIntQueue(); // Member functions void enqueue(int); void dequeue(int &); bool isEmpty() const; void clear(); }; main #include <iostream> #include "DynIntQueue.h" using namespace std; int main() {DynIntQueue list;...
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...
PART A - STACKS To complete this assignment: Please study the code posted below. Please rewrite the code implementing a template class using a linked list instead of an array. Note: The functionality should remain the same *************************************************************************************************************** /** * Stack implementation using array in C/procedural language. */ #include <iostream> #include <cstdio> #include <cstdlib> //#include <climits> // For INT_MIN #define SIZE 100 using namespace std; /// Create a stack with capacity of 100 elements int stack[SIZE]; /// Initially stack is...
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();...
Study the "Queue as linked list simple example" posted in this module. Rewrite the code to use array instead of linked lists. Please do not change anything besides the data structure. Instead of linked list use an array. The functionality should remain exactly the same. LListQueue.cpp ///--------------------------------------------------------------- /// File: LListQueue.cpp /// Purpose: Implementation file for a demonstration of a queue /// implemented as an array. Data type: Character /// Programming Language: C++ ///--------------------------------------------------------------- #include "LListQueue.h" ///-------------------------------------------- /// Function: LListQueue() ///...
To solve real world problem, the programer uses ADT like list, stack, queue, set, map, ... etc. to build our data model. In AS8, we pick and choose STL queue and stack to build a postfix calculator. In this assignment you are to Design your own linked-list, a series of integer nodes. The private attributes of this IntLinked Queue including a integer node struct and private control variables and methods: private: struct Node { int data; Node *next; }; Node...
Code in C++. Can someone make it so that the code below can be compiled? ▪ Creating an empty queue ▪ Inserting a value ▪ Removing a value ▪ Finding the size of the queue ▪ Printing the contents of the queue ▪ Adding the contents of one queue to the end of another ▪ Merging the contents of two queues into a third, new, queue Class Attributes Your class should be implemented using a linked list and should have...
Raphael was very happy last week until his boss suddenly called him yesterday, asking him to rewrite his code. Despite being terribly upset about it, he has finished up writing part of the code below. However, same as his predicament from last week, he doesn't understand how to complete the code to include functions for a) searching for a person and b) deleting the person at the front. Please help him complete his .cpp file ABOVE by defining the two...