Linked List Data Structure Implementation In C Language

Linked list is a data structure, a collection of data that each node in the list has reference to the next node and in a double linked list it can have a previous node. Linked lists are preferred to be used because of the efficiency in the insertion and deletion. Linked lists also can be used to implement other abstract data types  like stacks, queues, etc.

The basic idea of linked list is that it has a head Node that we can iterate the next node until we find the very last node or the tail node to find specific data, usually given an index or the position of the data.

In this post I created a simple reusable implementation of singly linked list in C, which probably is not very efficient in terms of speed and performance, but for me I feel like it’s much more human readable.

Run Linked List Demo

This implementation of linked list has features  that I will describe in a quick explanation below.

- List_init

To initialize the first node, or the head node if the linked list is empty or had been cleared

- List_length

To check the size of the list, will return the number of how many nodes are there that is in the list

- List_get (index)

To get specific node given an index of the list

- List_delete (index)

To delete specific node given a valid index on the list

- List_index_errno (index)

Verify whether a given index is a valid index on the list, for example a list that contains only 3 nodes will return error if the index is example given 3, 4 or more

- List_add(index)

Add new node to specific index location

- List_show

Iterate through the list and display the data

- List_push

Add a new data or node to the very last of the list

- List_unshift

Add a new data or node to the very beginning of the list

- List_pop

Will remove the tail node of the list

- List_shift

Will remove the head node of the list, and then replace the head node with the second node

- List_clear

Very self describe, which is to clear the linked list out of the memory

If you are interested in exploring the single linked list that we made, you can clone the project from this github repository below. Here’s a link to the project linked list github repo I described above.

git clone

This is just a very simple implementation of linked list data structure but yet it’s very interesting to learn about data structure implemented in the C language. The standard library of C language is very simple, so almost anything we need to make yourself a feature you are gonna work with. It has an array but the drawback with an array is that you need to specify the maximum number of items that could be on the array, so it wasn’t very dynamic.


Popular posts from this blog

ASUS Battery Health Charging Software To Make Your Battery Life Longer

How To Create Flutter Card With Example Code

How To Uninstall Angular CLI, The Angular Framework

ERROR 1348 Column Password Is Not Updatable When Updating MySQL Root Password

How To Create Spring Boot Project Using Netbeans