#include #include struct StrListElement { int value; struct StrListElement* next; }; int main() { struct StrListElement* head = NULL; //Head of the singly linked list struct StrListElement* str_elem_ptr; int i; for( i = 0; i < 5; i++) { //Create an element which is going to be added into the list str_elem_ptr = (struct StrListElement* ) malloc ( sizeof(struct StrListElement)); str_elem_ptr -> value = i; //Add new element to the head of the list str_elem_ptr -> next = head; head = str_elem_ptr; } //Traverse the whole list printf("Output the list:\n"); str_elem_ptr = head; while(str_elem_ptr != NULL) { printf("%d\n", str_elem_ptr->value); str_elem_ptr = str_elem_ptr -> next; } //Delete elements in the list from the head. Free the memory of deleted elements while(head != NULL) { str_elem_ptr = head; head = str_elem_ptr -> next; free(str_elem_ptr); } return 0; }