2010-10-01

General purpose linked list, stack and queue for C

Programmers refer to use modern programming languages like Java, Python or Ruby for their uses, because of their powerful built-in functions and flexibility. However, sooner or later, a programmer will have to face their old fella C someday.

For me, I had to use C when I decided to write an interpreter for a programming language I am developing. Of course, C lack of a bunch of stuff, which other modern languages have like hash table, and indexing of a list with a negative index (Python can do list[-2]), etc. But the first things I needed were stack, queue and linked list. We always write these ourselves when programming in C.

Here, I wrote a code for a linked list which can be used as stack and queue and supports negative indexing. Followings are the codes hosted on Google Code:

http://code.google.com/p/litelang/source/browse/trunk/litelang/slist.h (Includes description for methods)

http://code.google.com/p/litelang/source/browse/trunk/litelang/slist.c

Peace!