Run ❯
Get your
own
website
❯
Run Code
Ctrl+Alt+R
Change Orientation
Ctrl+Alt+O
Change Theme
Ctrl+Alt+D
Go to Spaces
Ctrl+Alt+P
#include
#include
struct Node { int data; struct Node *next; }; struct Node *createNode(int value) { struct Node *newNode = malloc(sizeof(struct Node)); if (newNode == NULL) { printf("Memory allocation failed\n"); exit(1); } newNode->data = value; newNode->next = NULL; return newNode; } void printList(struct Node *head) { struct Node *current = head; while (current != NULL) { printf("%d -> ", current->data); current = current->next; } printf("NULL\n"); } void freeList(struct Node *head) { while (head != NULL) { struct Node *next = head->next; free(head); head = next; } } int main() { struct Node *head = createNode(10); head->next = createNode(20); head->next->next = createNode(30); printList(head); freeList(head); return 0; }
10 -> 20 -> 30 -> NULL