Question description Professor Shiva decided to conduct an industrial visit for final year students, but he set a condition that if students received a passing grade in the surprise test, they would be eligible to go on the industrial visit. He asked the students to study a topic linked list for 10 minutes before deciding to conduct a surprise test. Professor-mandated questions, such as the deletion of nodes with a certain data D, are now being asked. For example if the given Linked List is 5->10->15->10->25 and delete after 10 then the Linked List becomes 5->15->25. Constraints 1< N < 100 1< D < 1000
C Program


#include <stdio.h>

#include <stdlib.h>

struct node {

    int data;

    struct node *next;

};

struct node *head = NULL;

int d, val;

void create() {

    struct node *t = malloc(sizeof(struct node));

    t->data = val;

    t->next = NULL;

    struct node **p = &head;

    while (*p) p = &(*p)->next;

    *p = t;

}

void del() {

    struct node dummy;

    dummy.next = head;

    struct node *p1 = &dummy, *p2;

    p2 = p1->next;

    while (p2) {

        if (p2->data == d) {

            p1->next = p2->next;

            free(p2);

            p2 = p1->next;

        } else {

            p1 = p2;

            p2=p2->next;

        }

    }

    head = dummy.next;

}

int main() {

    int n, i;

    scanf("%d", &n);

    for (i = 0; i < n; i++) {

        scanf("%d", &val);

        create();

    }

    scanf("%d", &d);

    del();

    struct node *t = head;

    printf("Linked List:");

    while (t) {

        printf("->%d", t->data);

        t = t->next;

    }

    printf("\n");

    return 0;

}