Write A Program in C To Create and Display Singly Linked List
Write A Program in C To Create and Display Singly Linked List
Sample Solution:
#include <stdio.h>
#include <stdlib.h>
struct node {
int data;
struct node *next;
};
printf("\n[head] =>");
//start from the beginning
while(ptr != NULL) {
printf(" %d =>",ptr->data);
ptr = ptr->next;
}
printf(" [null]\n");
}
//link->key = key;
link->data = data;
int main() {
insert(10);
insert(20);
insert(30);
insert(1);
insert(40);
insert(56);
printList();
return 0;
}
Output
Output of the program should be −
[head] => 56 => 40 => 1 => 30 => 20 => 10
=> [null]