7.Single Linked List in C adding a node at the end.

Опубликовано: 05 Июнь 2015
на канале: DASARI TUTS
2,804
10

A linked list is a collection of structures ordered not by their physical placement in memory but by logical links that are stored as part of the data in the structure itself. It is not necessary that it should be stored in the adjacent memory locations. Every structure has a data field and an address field. The Address field contains the address of its successor.Linked list can be singly, doubly or multiply linked and can either be linear or circular.

In linked data structures, the links are usually treated as special data types that can only be dereferenced or compared for equality. Linked data structures are thus contrasted with arrays and other data structures that require performing arithmetic operations on pointers. This distinction holds even when the nodes are actually implemented as elements of a single array, and the references are actually array indices: as long as no arithmetic is done on those indices, the data structure is essentially a linked one.

Example in C
===========
struct node
{
int val;
struct node *next;
};

In an array, the array elements have to be in a contiguous (connected and sequential) portion of memory. But in a linked data structure, the reference to each node gives users the information needed to find the next one. The nodes of a linked data structure can also be moved individually to different locations without affecting the logical connections between them, unlike arrays. With due care, a process can add or delete nodes to one part of a data structure even while other processes are working on other parts.

Compared to arrays, linked data structures allow more flexibility in organizing the data and in allocating space for it. In arrays, the size of the array must be specified precisely at the beginning, which can be a potential waste of memory. A linked data structure is built dynamically and never needs to be bigger than the programmer requires. It also requires no guessing in terms of how much space must be allocated when using a linked data structure. This is a feature that is key in saving wasted memory.


Смотрите видео 7.Single Linked List in C adding a node at the end. онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь DASARI TUTS 05 Июнь 2015, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 2,80 раз и оно понравилось 1 людям.