// Pantea Aria // linked list functions // Draw a linked list of three nodes with values 10, 20, and 30. // make linked lists with 3 nodes values 10, 20, and 30 // print each node's data using a function #include #include struct node { int data; struct node *next; }; void print_list(struct node *head); int main (void) { // declare, malloc and initialise for first node struct node *first = malloc(sizeof(struct node)); if (first == NULL) { // print the error return 1; } first->data = 10; // declare, malloc and initialise for second node first->next = malloc(sizeof(struct node)); // test if it is not NULL - your turn first->next->data = 20; // declare, malloc and initialise for third node first->next->next = malloc(sizeof(struct node)); // test if it is not NULL - your turn first->next->next->data = 30; // I must set the last node's next to NULL first->next->next->next = NULL; // print out all values printf("%d %d %d\n", first->data, first->next->data, first->next->next->data); // cal print_list print_list(first); return 0; } void print_list(struct node *head) { // make a temporary pointer to travers my linked list struct node *current = head; while (current != NULL) { printf("%d ", current->data); current = current->next; } printf("\n"); }