Question description the popular engineering college got lowest pass percentage in last semester. the principal conducted faculty meeting and decided to visit all the classes surprisingly. Dr.Ramprasath is a faculty, who handling data structure course for EEE department second year students. one day this faculty was handling very interesting topic in data structure such that Linked List, During this lecture time, principal surprisingly visited to the class and asking to conduct surprise test on Linked list concept. So the faculty decided to conduct test on the topic of Linked List. the question was given to last bench students that is, The nodes are deleted before a certain given node in the linked list. For example if the given Linked List is 5->10->15->20->25 and delete before 15 then the Linked List becomes 15->20->25.
C Program


#include<stdio.h>

#include<stdlib.h>

struct node{

int data;

struct node *next;

};

struct node *head=NULL;

int n,key;

void create()

{

int i,x;

struct node *t,*nn;

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

{

scanf("%d",&x);

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

nn->data=x;

nn->next=NULL;

if(head==NULL) head=t=nn;

else t=t->next=nn;

}

}

void del()

{

struct node *p1=head,*p;

while(p1&&p1->data!=key) p1=p1->next;

if(!p1)

{

printf("Invalid Node! Linked List:->");

for(p=head;p;p=p->next) printf("%d%s",p->data,p->next?"->":"");

return;

}

printf("Linked List:->");

for(p=p1;p;p=p->next) printf("%d%s",p->data,p->next?"->":"");

}

int main()

{

scanf("%d",&n);

create();

scanf("%d",&key);

del();

}