﻿ C Program: Delete alternate nodes of a singly linked list

# C Exercises: Delete alternate nodes of a singly linked list

## C Singly Linked List : Exercise-33 with Solution

Write a C program to delete alternate nodes of a singly linked list.

Sample Solution:

C Code:

``````#include<stdio.h>
#include <stdlib.h>

struct Node {
int data;
struct Node * next;
};

struct Node * newNode(int data) {
struct Node * temp = (struct Node * ) malloc(sizeof(struct Node));
temp -> data = data;
temp -> next = NULL;
return temp;
}

void printList(struct Node * head) {
}
printf("\n");
}

while (curr != NULL) {
prev->next = curr->next;
free(curr);
prev = prev->next;
if (prev != NULL)
curr = prev->next;
}
}
int main() {
struct Node * head = newNode(1);
head -> next -> next = newNode(3);
head -> next -> next -> next = newNode(4);
head -> next -> next -> next -> next = newNode(5);
head -> next -> next -> next -> next -> next = newNode(6);
head -> next -> next -> next -> next -> next -> next = newNode(7);
printf("Original List:\n");
printf("\nDelete alternate nodes of the said singly linked list:\n");
return 0;
}
```
```

Sample Output:

```Original List:
1 2 3 4 5 6 7

Delete alternate nodes of the said singly linked list:
1 3 5 7
```

Flowchart :

C Programming Code Editor:

What is the difficulty level of this exercise?

﻿