This project involved implementing a Queue data structure in C++ as part of a university assignment. The Queue follows the FIFO (First-In-First-Out) principle, where elements are added to the end (enqueue) and removed from the front (dequeue). The implementation highlights fundamental concepts of dynamic memory allocation and linked list structures in C++.
My version of queue is implemented using a custom node structure, where each node stores a double value and a pointer to the next node. The create_queue() function initializes the queue with a single node.
The enqueue() function adds new nodes to the end of the queue by traversing the linked list to find the last node and updating its next pointer. The dequeue() function removes the front node by updating the head pointer to the next node and disconnecting the removed node.
To ensure memory management, the delete_queue() function iterates through the entire queue, deleting each node to free allocated memory. The print_queue() function provides a clear view of the queue's contents by iterating through the nodes and displaying their values along with their positions.
We use cookies to analyze website traffic and optimize your website experience. By accepting our use of cookies, your data will be aggregated with all other user data.