This can be fixed by simply declaring temp.
Taiwo A.
asked 04/27/22HOW CAN THIS ERROR BE FIXED?
inlab21.cpp: In member function ‘DataType Queue::dequeue()’:
inlab21.cpp:28:2: error: ‘temp’ was not declared in this scope
temp=frontPtr
================================
// This is the default constructor.
Queue::Queue()
{
frontPtr = NULL;
rearPtr = NULL;
} // end default constructor
//qEmpty tests for an empty queue.
int Queue::qEmpty() const
{
return frontPtr == NULL;
} // end qEmpty
// This function takes the front element off of the queue. It assumes
// that the queue is not empty. Call 'qEmpty()' before calling this
// function to ensure that this is the case.
DataType Queue::dequeue()
{
temp=frontPtr
frontPtr=frontPtr->next
free(temp)
} // end enqueue
// This function adds an element to the rear of the queue.
void Queue::enqueue(const DataType& item)
{
NodePtr newPtr = new QueueNode;
newPtr->data = item;
newPtr->next = NULL;
if (qEmpty()) //Was the queue empty?
{
frontPtr = newPtr;
rearPtr = newPtr;
}
else
{
rearPtr->next = newPtr;
rearPtr = newPtr;
}
} // end enqueue
1 Expert Answer
Still looking for help? Get the right answer, fast.
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.