#header-inner {background-position: right !important; width: 100% !important;}


How to implement linked list using arrays.

Pointers are useful but not every programming language allows to use them. I'll show how to implement Linked List using arrays and idea of pointer data type.

Linked List node consists of value and address pointing to another variable.

We need address space which can be implemented with 2D array (one column can be memory address, another can point to another (or same) variable written under another (or same) address.

Then we can build Linked List (consisting of 2-field arrays, first field being value contained in node, second field is pointer to next node or null).

Hint: If we have pointers we can construct objects in any language with arrays. Then we can make Finite State Objects, Stitie machine and so on..

No comments:

Post a Comment