|
List->Dynamic List->Concept |
||
| Well, my favorite topic,
because here starts that chain reaction; you would know what I mean
after sometime!
We have seen STATIC list, ARRAY, in which, we realised that space is the constraint. At the run-time, it was not possible to add more space to the existing allotted space to the LIST. Now, solution lies here with the advent of Dynamic Linked Lists. What it does is -- starts with no fixed size and accumulates memory as and when needed (using garbage collection techniques); what you get in turn is no data overflow, no wastage of memory but a little more computation time. Let's understand... Dynamic
LIST:
So, every linked list has a POINTER to the list, which holds the list. In this case, it is "list". If you loose this pointer, you will loose the list. What I mean is - you have to have a pointer always pointing to the beginning of the list. Now the question is, how do you create a NODE? In C, you have memory handling functions like malloc() and free(), which do the job of allocating and freeing of memory space for you; defined in alloc.h header file. So simple! So, to get a fresh NODE, just call malloc() by providing it the size of your NODE and it allocates you that much of memory space. COOL no! Well, its hardly of our concern from where it collects that memory space. With all that background, I think, we can create a Linked list... Algorithm:- C implementation:- Note:- Remember that the "nodevalue" we have taken here can be anything - an integer or a character or an array, .....or any damn process. Well, programming languages like JAVA does all these memory operations on its own to make the programming simpler! Related Operations: |
||
| Index || Doubts / Clarifications || Related Topics || Web Links | ||