Finance[US] Career Guide Free Tutorials Go to Your University Placement Preparation 
1 like 0 dislike
12.5k views
in VTU B.Tech (CSE-III Sem) Data Structure Lab by Goeduhub's Expert (7.6k points)
edited by

Design, Develop and Implement a menu driven Program in C for the following operations on Singly Linked List (SLL) of Student Data with the fields: USN, Name, Programme, Sem,PhNo

  • Create a SLL of N Students Data by using front insertion.
  • Display the status of SLL and count the number of nodes in it
  • Perform Insertion / Deletion at End of SLL
  • Exit

1 Answer

0 like 0 dislike
by Goeduhub's Expert (7.6k points)
edited by
 
Best answer

Design, Develop and Implement a menu driven Program in C for the following operations on Singly Linked List (SLL) 

A linked list is a linear data structure, in which the elements are not stored at contiguous memory locations. 

image

  • A node contains two fields i.e. data stored at that particular address and the pointer which contains the address of the next node in the memory.
  • The last node of the list contains pointer to the null.

The simplest kind of linked list is a singly liked list (SLL) which has one link per node. It has two parts, one part contains data and other contains address of next node. In simple words, a linked list consists of nodes where each node contains a data field and a reference(link) to the next node in the list.The structure of a node in a SLL is given as in C: 

struct node

{

    int data;

    struct node *next;

};

Insertion of node at front 

  1. allocate node
  2. put in the data
  3. Make next of new node as head
  4. move the head to point to the new node

void insert(struct Node** head_ref, int new_data)

{

    struct Node* new_node = (struct Node*) malloc(sizeof(struct Node));

    new_node->data  = new_data;

    new_node->next = (*head_ref);

    (*head_ref)    = new_node;

}

 image

Insertion at end

  1. allocate node
  2. put in the data 
  3. This new node is going to be the last node, so make next  of it as NULL
  4. If the Linked List is empty, then make the new node as head
  5. Else traverse till the last node
  6. Change the next of last node

void end(struct Node** head_ref, int new_data)

{

    struct Node* new_node = (struct Node*) malloc(sizeof(struct Node));

    struct Node *last = *head_ref;  

    new_node->data  = new_data;

    new_node->next = NULL;

    if (*head_ref == NULL)

    {

       *head_ref = new_node;

       return;

    }  

    while (last->next != NULL)

        last = last->next;

    last->next = new_node;

    return;    

}

 image

Insertion after a node

image

void insertAfter(struct Node* prev_node, int new_data)

{

    // check if the given prev_node is NULL  

    if (prev_node == NULL) 

    { 

       printf("the given previous node cannot be NULL");       

       return;  

    }         

    // allocate new node

    struct Node* new_node =(struct Node*) malloc(sizeof(struct Node));  

    //put in the data 

    new_node->data  = new_data;

    //Make next of new node as next of prev_node

    new_node->next = prev_node->next; 

    //move the next of prev_node as new_node

    prev_node->next = new_node;

}

Deletion of node 

To delete a node from linked list, we need to do following steps.
1) Find previous node of the node to be deleted.
2) Change the next of previous node.
3) Free memory for the node to be deleted.

kimge

void deleteNode(struct Node **head_ref, int key)

{

    // Store head node

    struct Node* temp = *head_ref, *prev;

  

    // If head node itself holds the key to be deleted

    if (temp != NULL && temp->data == key)

    {

        *head_ref = temp->next;   // Changed head

        free(temp);               // free old head

        return;

    }

  

    // Search for the key to be deleted, keep track of the

    // previous node as we need to change 'prev->next'

    while (temp != NULL && temp->data != key)

    {

        prev = temp;

        temp = temp->next;

    }

  

    // If key was not present in linked list

    if (temp == NULL) return;

  

    // Unlink the node from linked list

    prev->next = temp->next;

  

    free(temp);  // Free memory

}


For program Click Here


For more Visvesvaraya Technological University(VTU) CSE-III Sem Data Structure Lab Experiments Click Here


Learn & Improve In-Demand Data Skills Online in this Summer With  These High Quality Courses[Recommended by GOEDUHUB]:-

Best Data Science Online Courses[Lists] on:-

Claim your 10 Days FREE Trial for Pluralsight.

Best Data Science Courses on Datacamp
Best Data Science Courses on Coursera
Best Data Science Courses on Udemy
Best Data Science Courses on Pluralsight
Best Data Science Courses & Microdegrees on Udacity
Best Artificial Intelligence[AI] Courses on Coursera
Best Machine Learning[ML] Courses on Coursera
Best Python Programming Courses on Coursera
Best Artificial Intelligence[AI] Courses on Udemy
Best Python Programming Courses on Udemy

Related questions

 Important Lists:

Important Lists, Exams & Cutoffs Exams after Graduation PSUs

 Goeduhub:

About Us | Contact Us || Terms & Conditions | Privacy Policy ||  Youtube Channel || Telegram Channel © goeduhub.com Social::   |  | 

 

Free Online Directory

...