Linked lists and other structures In C

The combination of structures and pointers opens up a lot of interesting possibilities. It will go on describe one very common example: linked lists. It consists of structures containing pointers to other structures, all the structures typically being of the same type.

A single linked list is also called as one – way list. It is a linear collection of data elements, called nodes, where the linear order is given by means of pointers. Each node id divided into two parts.

  • i) Information
  • ii) Pointer to next node

A linked list consists of a series of structures which are not necessarily contiguous. Each structure contains one or more than one information fields and a pointer to a structure containing its successor. The pointer field of the last node contains a special value, called NULL pointer (‘\0’), which is any invalid address.

img

A linked list is a collection of nodes of the same type and hence it can be declared as

struct node
{
    int info;
    struct node *next;
};
img
Traversing a single linked list

Let a single linked list is in memory and we went to traverse the list inorder to process each node exactly once. Our aim is to traverse the list starting from the first node to the end of the list. Consider a pointer type variable node that pointes to the node currently being processed and next [node] points to the next node.



About the Author



Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.

We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc





 PreviousNext