SOURCE CODE:
#include<stdlib.h>
#include<stdio.h>
struct node{
int data;
struct node* next;
};
void printLL(struct node *ptr){
while(ptr != NULL){
printf("element = %d \n",ptr->data);
ptr=ptr->next;
}
}
struct node * delatindex(struct node* head,int index ){
struct node* p=head;
struct node* q=head->next;
for (int i=1;i<index-1;i++)
{
p=p->next;
q=q->next;
}
p->next=q->next;
free(q);
return head;
}
int main()
{ struct node* head;
struct node* second;
struct node* third;
head=(struct node*)malloc(sizeof(struct node));
second=(struct node*)malloc(sizeof(struct node));
third=(struct node*)malloc(sizeof(struct node));
head->data=11;
head->next=second;
second->data=55;
second->next=third;
third->data=66;
third->next=NULL;
printf("linked list before deletion \n");
printLL(head);
printf("linked list after deletion \n");
head=delatindex(head,2);
printLL(head);
return 0;
}
OUTPUT:
element = 11
element = 55
element = 66
linked list after deletion
element = 11
element = 66
0 Comments