Practical Name : Write a ‘C’ program to create a singly Link list and display its alternative nodes. (start displaying from first node)
#include <stdio.h> #include <stdlib.h> struct Node {
int data;
struct Node* next;
};
void printAlternateNode(struct Node* head)
{
int count = 0;
while (head != NULL) {
if (count % 2 == 0)
printf(" %d ", head->data);
count++;
head = head->next;
}
REMARK:-
}
void push(struct Node** head_ref, int new_data)
{
struct Node* new_node =
(struct Node*)malloc(sizeof(struct Node)); new_node->data = new_data;
new_node->next = (*head_ref); (*head_ref) = new_node;
}
int main()
{
struct Node* head = NULL; push(&head, 23);
push(&head, 42);
push(&head, 17);
push(&head, 34);
push(&head, 5);
printAlternateNode(head);
return 0;
}