Linked List Node in C
Level 4249 keystrokes
Creates a simple linked list structure and traverses it using a while loop.
C code
// Self-referential structure for linked list1struct Node {2 int data; // Pointer to next node3 struct Node *next;4};5 // Create the last node first so the others can take its address6struct Node n3 = {30, NULL};// n2 points to n37struct Node n2 = {20, &n3};// n1 points to n28struct Node n1 = {10, &n2};9 // Start traversal from first node10struct Node *curr = &n1;// Loop until we reach NULL11while (curr != NULL) { // Print current node's data12 printf("%d -> ", curr->data); // Move to next node13 curr = curr->next;14}// After the last node, mark the end of the list15printf("NULL\n");Output
10 -> 20 -> 30 -> NULL
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this C code and how often they appear.
;× 10=× 6{× 5}× 5,× 4"× 4-× 3(× 3)× 3&× 3