Skip to content

How Exception is Avoided in dequeue() #1

Open
@Shenouda-Fawzy

Description

@Shenouda-Fawzy

While we are dequeuing items from the queue, if we reach the last item both front and rearpointing to the last item, and the front will have the value of NULL the we delete the address of rear using the temp pointer, so the rear will be pointing to nothing so it must be marked as NULL to indicate we reach the end of the queue.

this is the code snippet I'm talking about:

ItemType dequeue()
{
if (isEmpty())
throw EmptyQueue();
else
{
NodeType* temp = front;
ItemType item = front->info;
front = front->next;
// We reach the end and if we delete the rear will be pointing to nothing so we put it to NULL.
if (front == NULL)
rear = NULL;
delete temp;
return item;
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    InformativeExplain a piece of Code

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions