Linked List Node in C
Level 5289 keystrokes
Declares a self-referential Node struct, creates three nodes holding 10, 20 and 30, links them through their next pointers and walks the list from the first node until NULL, printing 10 20 30.
C code
// A self-referential struct: it contains a pointer to its own type1struct Node { // The value stored in the node2 int data; // Pointer to the next node of the same type3 struct Node *next;4};5 // Creates three unlinked nodes; each next starts as NULL6struct Node n1 = {10, NULL};7struct Node n2 = {20, NULL};8struct Node n3 = {30, NULL};// Links n1 → n2 → n3; n3.next stays NULL and ends the list9n1.next = &n2;10n2.next = &n3;11 // Starts the traversal at the first node12struct Node *current = &n1;// Follows the next pointers until NULL, the end of the list13while (current != NULL) { // Prints the current node's data: 10, then 20, then 3014 printf("%d ", current->data); // Moves to the next node15 current = current->next;16}// Ends the output line17printf("\n");Output
10 20 30
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.
;× 12=× 8{× 5}× 5,× 4"× 4(× 3)× 3&× 3-× 2