List as a data structure C

Self-referential data structures are useful in applications that involve linked data structures such as lists, trees and graphs. One structure will represent one component of the list. Each component of the list is called a node. The self-referential pointer indicates where the next component is located. Thus it links one component of list with another.

struct emp identifies a structure consisting of two members, an integer and a pointer (next) to another structure of same type. ‘start’ is an external pointer to struct emp. It will indicate the beginning of linked list.

List as a data structure

Pointer to next node is assigned a value of NULL until next node is created.
All operations on linked list, i.e. changing order of nodes, adding nodes, deleting nodes etc. can be done easily since only the pointer has to be altered.

There are several different kinds of linked data structures.
Linear linked list : In this components are linked together in sequential manner.
Doubly linked list : Here multiple pointers permit forward and backward traversal within the list.
Circular linked list : In which the last node points to the first node.
Trees : Here components are arranged hierarchically.

Here we will study linear linked lists.

Representation of linked list

Representation of linked list

Since 3rd node is the last node, NULL value is assigned to next node pointer. Thus NULL detects end of list.
Implementing list operations

  • Creating a node.
  • Inserting a node.
  • Displaying a list.
  • Deleting a node.

Whatever be the application which uses linklist, the basic operations are creating a node, insertion of a node, deleting a node and displaying the list. Here we explain the operations and write a function for each of them. At the end we write a program that combines all the operations on a list.

Face Book Twitter Google Plus Instagram Youtube Linkedin Myspace Pinterest Soundcloud Wikipedia

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd Protection Status

C Topics