/* Constructor for the Queue data structure*/ struct queue *newQueue(){ struct queue *q = malloc(sizeof(struct queue)); q->front = newQueueNode(); q->rear = newQueueNode(); q->size = 0; return q; }
void addToQueue(queueNode **head, node *nodeAdd) { if (*head == NULL) { *head = newQueueNode(nodeAdd); (*head)->next = NULL; return; } queueNode* lastNode = *head; while(lastNode->next != NULL) lastNode = lastNode->next; lastNode->next = newQueueNode(nodeAdd); }
// The function to add a key k to q void enQueue(struct Queue *q, struct binaryTreeNode *k) { // Create a new LL node struct queueNode *temp = newQueueNode(k); // If queue is empty, then new node is front and rear both if (q->rear == NULL) { q->front = q->rear = temp; return; } // Add the new node at the end of queue and change rear q->rear->next = temp; q->rear = temp; }