Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
Node is saved as draft in My Content >> Draft
  • Singular Linked List in C

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 206
    Comment on it

    Linked list is collection of nodes which contain the two parts the data and the address of the next node to which it is connected.

     

    Singular Linked List

     

    In singular linked list the node contains two parts as we have discussed the first one is the data part and the other one is the address of the next node as depicted in figure.

     

    Linked List

     

    Operation performed in Singular linked list

     

    • Insertion − add element at beginning .

    • Deletion − delete an element from the beginning of the list.

    • Display − displaying complete list.

    • Search − search an element using given key.

    • Delete − delete an element using given key.

     

    Insertion Operation

    In insertion we will create a node first then we will assign data into it then we will point the next location of the node to its second part

    Linked List Insert First

     

     

    //insert link at the first location
    void insertFirst(int key, int data){
       //create a link
       struct node *link = (struct node*) malloc(sizeof(struct node));
       link->key = key;
       link->data = data;
    	
       //point it to old first node
       link->next = head;
    	
       //point first to new first node
       head = link;
    }

     

     

    Deletion Operation

     

    In deletion operation we will delete the node by removing its data and removing the address reference  that it holds.

     

    Linked List Delete First

     

    //delete first item
    struct node* deleteFirst(){
       //save reference to first link
       struct node *tempLink = head;
    	
       //mark next to first link as first 
       head = head->next;
    	
       //return the deleted link
       return tempLink;
    }

     

    .net

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: