#include<stdio.h>
#include<stdlib.h>
struct Node {
int data;
struct Node *next;
};
void printList(struct Node *n)
{
while (n!=NULL) {
printf(" %d|\t", n->data);
n = n->next;
}
}
int main () {
struct Node* head = NULL;
struct Node* second = NULL;
struct Node* third = NULL;
struct Node* fourth = NULL;
struct Node* fifth = NULL;
head = (struct Node*)malloc(sizeof(struct Node));
second = (struct Node*)malloc(sizeof(struct Node));
third = (struct Node*)malloc(sizeof(struct Node));
fourth = (struct Node*)malloc(sizeof(struct Node));
fifth = (struct Node*)malloc(sizeof(struct Node));
head-> data = 1;
head->next = second;
second->data = 2;
second->next = third;
third->data = 3;
third->next = fourth;
fourth->data = 4;
fourth->next = fifth;
fifth->data = 5;
fifth->next = NULL;
printList(head);
delete();
printList(head);
}
void delete(){
struct Node* temp;
int loc;
printf("Enter the location what you want to delete : ");
scanf("%d",&loc);
if(loc>length()){
printf("Invailid Location");
}
else if (loc==1) {
temp = root;
root= temp -> next;
temp -> next = NULL;
free (temp);
}
}
There is a error in root variable and delete function. It says no deceleration of root variable. And previous implicit declaration of 'delete' was here Is it need to declare root variable first? If yes, where is want to be? Please let me know what is the error in this program.