HOME
PRIVACY POLICY
ABOUT US

C Program for beginners in link list with student details managing example

Environment Requirement

  • We will developing our program in Visual Studio Code and GCC compiler . To get it setup for you follow this link .


Prerequisite

  1. Basic Syntax and concept of C . If you haven't know yet kindly follow this link to learn basic concept and syntax
  2. Basic Knowledge about link list . We can read it from here


Implemention

  • First Create Structure of Student to store value in it .
  • We will Create Structure of name student and define inside five properties which is roll number,name,address, Telephone , Standard and one pointer which will store location of its next node . From that location we will access the other node . Roll number will be used to search Student .


  • Now we have change new added pointer to head pointer . As For First node previous is NULL how New added node will point to Null and header to new Node . We will give this function name is prepend
  • For traverse the link list we will create on function name traverse . Which will traverse from first to the node those pointer point to null which is last Node . It will be mainly used to search, Update and Delete We will see the later section
  • Some times We need to count the node . we will use traverse function to count node . By just increasing counter in it .

Insert Operation


  • We Can Add Node the end of link list
  • We Can Add Node in the middle of link list
  • We Can Add Node in the start of Link List


For Our Example we will adding node in start of Link List Means . Which we will prepend

Search Operation

To search for a node that stores a given data, we scan the whole list and return the first node that stores the searched data . We will be searching node by using roll number of students. The following illustrates the search function:

Update Operation

We will Update node first by searching through roll number as we get the pointer we can change its name and address only now .

Delete Operation


We Can Delete Node From Start , End and From the middle . But in this example we will be deleteing on the basis of roll number . First we have to find is it first node , middle node or last after finding it . we Will delete it on the basis of our previous review .



  • To delete a first node of the linked list is relatively simple. We point the head to the next node and remove the node that the head pointed to. For Delete we will use free function release that memory

Delete Node From the end


  • To Delete Pointer from the end we need to use two pointers . In Which one pointer moves ahead of second pointer . When First Pointer reaches end Means able to find NULL pointer which is end . We will delete node of second pointer which point to the end Node . Following Diagram illustrate that

Delete Node from Middle


  • Here Also we will be using two Pointers one temp on cursor . temp always move to find selected node as we find the selected node we will Assign selected node pointer to the previous node and to which now cursor is pointing and delete temp pointer node . Following example illustrate that

Full Implementation code Given Below copy and Paste code in Visaual Studio code with file name linklist.c and click ctrl+` to open Terminal and type command

GCC linklist.c

./a (to run application)

Taher Software Engineer

Related Posts