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;
list.enqueue(32);
list.enqueue(&num);//this member function call seems to be causing issues.
// list.isEmpty();
list.clear();
//Pause the program until input is received
int num=1;
return 0;
}
cpp
DynIntQueue::DynIntQueue()
{
front = nullptr;
rear = nullptr;
}
//************************
// Destructor. *
//************************
DynIntQueue::~DynIntQueue()
{
QueueNode * garbage = front;
while (garbage != nullptr)
{
front = front->next;
garbage->next = nullptr;
delete garbage;
garbage = front;
}
}
//********************************************
// Function enqueue inserts the value in num *
// at the rear of the queue. *
//********************************************
void DynIntQueue::enqueue(int num)
{
if (isEmpty())
{
front = new QueueNode(num);
rear = front;
}
else
{
rear->next = new QueueNode(num);
rear = rear->next;
}
}
//**********************************************
// Function dequeue removes the value at the *
// front of the queue, and copies it into num. *
//**********************************************
void DynIntQueue::dequeue(int &num)
{
QueueNode *temp = nullptr;
if (isEmpty())
{
cout << "The queue is empty.\n";
exit(1);
}
else
{
num = front->value;
temp = front;
front = front->next;
delete temp;
}
}
//*********************************************
// Function isEmpty returns true if the queue *
// is empty, and false otherwise. *
//*********************************************
bool DynIntQueue::isEmpty() const
{
if (front == nullptr)
return true;
else
return false;
}
//********************************************
// Function clear dequeues all the elements *
// in the queue. *
//********************************************
void DynIntQueue::clear()
{
int value; // Dummy variable for dequeue
while (!isEmpty())
dequeue(value);
}
#######################################
DynIntQueue.cpp
#######################################
#include "DynIntQueue.h"
DynIntQueue::DynIntQueue()
{
front = nullptr;
rear = nullptr;
}
//************************
// Destructor. *
//************************
DynIntQueue::~DynIntQueue()
{
QueueNode * garbage = front;
while (garbage != nullptr)
{
front = front->next;
garbage->next = nullptr;
delete garbage;
garbage = front;
}
}
//********************************************
// Function enqueue inserts the value in num *
// at the rear of the queue. *
//********************************************
void DynIntQueue::enqueue(int num)
{
if (isEmpty())
{
front = new QueueNode(num);
rear = front;
}
else
{
rear->next = new QueueNode(num);
rear = rear->next;
}
}
//**********************************************
// Function dequeue removes the value at the *
// front of the queue, and copies it into num. *
//**********************************************
void DynIntQueue::dequeue(int &num)
{
QueueNode *temp = nullptr;
if (isEmpty())
{
cout << "The queue is empty.\n";
exit(1);
}
else
{
num = front->value;
temp = front;
front = front->next;
delete temp;
}
}
//*********************************************
// Function isEmpty returns true if the queue *
// is empty, and false otherwise. *
//*********************************************
bool DynIntQueue::isEmpty() const
{
if (front == nullptr)
return true;
else
return false;
}
//********************************************
// Function clear dequeues all the elements *
// in the queue. *
//********************************************
void DynIntQueue::clear()
{
int value; // Dummy variable for dequeue
while (!isEmpty())
dequeue(value);
}
#######################################
DynIntQueue.h
#######################################
#include<iostream>
#include<cstdlib>
using namespace std;
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.cpp
#######################################
#include <iostream>
#include "DynIntQueue.h"
using namespace std;
int main()
{
DynIntQueue list;
cout << "Enqueuing the nummber 32." << endl;
list.enqueue(32);
// declare a variable in which dequeued data from the
// queue will be filled in.
int num;
// pass num to function, the function fills the value
list.dequeue(num);
// print the filled data
cout << "Dequeued number: " << num << endl;
// list.isEmpty();
list.clear();
return 0;
}
i have given comments to make you understand on whats happening.. If still any issues, please ask in comments. If you find it helpful, please upvote.
How do I pass values to this function? class DynIntQueue { struct QueueNode { int value;...
Write a function that takes a string parameter and determines whether the string contains matching grouping symbols. Grouping symbols are parenthesis ( ) , brackets [] and curly braces { }. For example, the string {a(b+ac)d[xy]g} and kab*cd contain matching grouping symbols. However, the strings ac)cd(e(k, xy{za(dx)k, and {a(b+ac}d) do not contain matching grouping symbols. (Note: open and closed grouping symbols have to match both in number and in the order they occur in the string). Your function must use...
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() ///...
I need help fixing my code. My output should be the following. Hello, world! : false A dog, a panic in a pagoda : true A dog, a plan, a canal, pagoda : true Aman, a plan, a canal--Panama! : true civic : true If I had a hi-fi : true Do geese see God? : true Madam, I’m Adam. : true Madam, in Eden, I’m Adam. : true Neil, a trap! Sid is part alien! : true Never odd...
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; }...
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...
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();...
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...
Using the below files, Write a program that reads a document containing endnotes indicated in this manner, collects them in a queue, and prints them on the screen. For this lab, you will create a text file called sample.txt and put the following paragraph in it. This part is the beginning. {This part is the footnote.} This part is the end. /* Queue.h contains the declaration of class Queue. Basic operations: Constructor: Constructs an empty queue empty: Checks if a...
I'm trying to implement a queue using an array within C++. I cannot for the life of me figure out why some of my methods are not working properly. My exists method does not find a value that's in the queue and my duplicate method is duplicating the rear of my queue instead of the front. The duplicate method should take whatever is at the front of the queue (given it's not empty or full), copy that value, and put...