Steven Lynn’s Blog

FP-style linked list in C

2025-1-21341 words2 min read
Linked list is a basic lesson in C, but it's fun to implement them.

Define the structure

constructor

Why write this, because each manual malloc will be redundant, borrowed from the C++ new
Classic interview question, the difference between new and malloc
but cpp suggests using unique_ptr instead of bare pointers
About malloc without type conversion
 

Constructing a linked table

Print the linked table

nth

join_list

Insert node after

for example

delete nth node

it has boundary problem, use empty node to solve it.

free

main

valgrind test ok

 
Loading...