Professional Documents
Culture Documents
Introduction
• Linked lists are special list of some data elements linked to one
another. The logical ordering is represented by having each element
pointing to the next element.
• Each element is called a node, which has two parts.
• INFO part which stores the information and
• POINTER which points to the next element.
• "A linked list is a linear collection of data elements, called node
pointing to the next nodes by means of pointers."
• Each node is divided into two parts.
1. The first part contains the information ofthe element [INFO]
2. The second part called the link field contains the address of the next node
in the list [POINTER]
Linked List
• The last node contains a null link
• The list may (or may not) have a header
• A node ' s successor is the next node in the sequence
• The last node has no successor
• A node ' s predecessor is the previous node in the sequence
• The first node has no predecessor
• A list ' s length is the number of elements in it
• A list may be empty (contain no elements)
• The Head is a special pointer variable which contains the address of
the first node of the list.
• If there is no node available in the list then Head contains NULLvalue
that means, List is empty.
• The left part of the each node represents the information part of the
node
• which may contain an entire record of data (e.g. ID, name, marks, age etc)
• The right part represents pointer/link to the next node
• The next pointer of the last node is null pointer signal the end of the
list.
Normal Way to Draw a Linked List
Advantages
• Linked lists are dynamic data structures. That is, they can grow or
shrink during the execution of a program.
• Effcient memory utilization. Here memory is not pre-allocated.
Memory is allocated whenever it is required. And it is deallocated
(removed) when it is no longer needed.
• Insertion and deletion are easier and efficient. Linked lists provide
flexibility in inserting a data item at a specified posotion and
deletionof a data item from the given position.Many complex
applications can be easily carried out with linked lists.
Disadvantage
• More memory: if the number of fields are more, then more memory
space is needed.
• Searching a particular element in list is difficult and also time
consuming.
The linked list code will depend on the
following functions:
• Malloc() is a system function which allocates a block ot memory in
the "heap" and returns a pointer to the new block.