Implement Queue in C Singly Linked List

Yu-Ming, CHANG (he/him)
1 min readJan 29, 2022

This series is written for the purpose of supporting my self learning journey to become professional web developer. The complete article structure could be found in Technical Article Structure on Medium.

Introduction

The concept of Queue and Singly Linked List were covered in previous post.

Implementation

There are 9 functions we need to implement, one of which is for debugging purpose.

  1. declare a node structure
  2. create newNode() to create a function to dynamically allocate memory space for a new node
  3. create enQueue() to append node to the linked list
  4. create deQueue() to remove front node from the list
  5. create countQueue() to get current size of linked list
  6. create deleteNode() to remove node with specified value
  7. create rear() to return the value for the last node
  8. create freeList() to free up memory
  9. (optional) create printList() to debug

Note: In the gist example, you’ll notice that even after we free up memory for the linked list, we are still able to print the linked list. The reason behind is that free() allows memory to be reused later, but not to erase the content. Although, it may work in one computer, it is not a guarantee that reference to original head will work in the future

Gist Example

--

--

Yu-Ming, CHANG (he/him)

I enjoy the positive mind flow when writing code to solve a problem. This is my journey to become a software developer, though now working as a product owner