// Pantea Aria // linked list introduction // What is a linked list? How is it different from an array? static memory // collection of same data type - dynamic memory in linked list malloc // Draw a linked list of three nodes with values 10, 20, and 30. // What does the last node of a singly linked list point to? NULL // make linked lists with 3 nodes, print each node's data #include #include struct node { int data; struct node *next; }; int main (void) { // declare, malloc and initialise for first node struct node *first = malloc(sizeof(struct node)); // always check if it is not returning NULL your turn first->data = 10; first->next = NULL; // declare, malloc and initialise for second node struct node *second = malloc(sizeof(struct node)); // always check if it is not returning NULL your turn second->data = 20; second->next = NULL; // declare, malloc and initialise for third node struct node *third = malloc(sizeof(struct node)); // always check if it is not returning NULL your turn third->data = 30; third->next = NULL; // link first to second // I must update the first node's next first->next = second; // link second to third // I must update the next of second node second->next = third; // print out all values using first node printf("%d %d %d\n", first->data, first->next->data, first->next->next->data); // print all next printf("%p %p %p\n", first, first->next, first->next->next); printf("%p %p %p\n", first, second, third); free(first); free(second); free(third); return 0; }