Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic list in ANSI C?

Tags:

c

Am i right in thinking the only way to create a list which grows during run time in C, is to use a linked list?

like image 453
Tom Avatar asked Oct 31 '10 16:10

Tom


People also ask

What is meant by dynamic list?

A dynamic list combines the power and flexibility that a fragment would have with contribution capabilities. The dynamic list performs a query in the content server, displays the files that match that query, and allows contributors to modify those files, even add new ones.

Is STD list dynamic?

Why not use the std::vector or std::list class instead of writing your own? Both are dynamically-growing lists.

Are lists dynamic in C++?

Linked lists are the best and simplest example of a dynamic data structure that uses pointers for its implementation.


1 Answers

You could use a combination of malloc and realloc. To first initialize a C array (malloc) and to grow it (realloc). However, you won't want to grow it by 1 element at a time if you are doing a lot of inserts. It's best to come up with a scheme to make the list grow as you need it (ie add 10 elements each time the list size reaches the allocated size).

like image 57
GWW Avatar answered Oct 31 '22 20:10

GWW