#include #include struct node { int value; struct node *next; }; struct node *front; void add_to_back(int v); void remove_from_front(); void print_list(); int main() { int value; while (1) { printf("Enter a number: "); int rtn = scanf("%d", &value); if (rtn != 1) break; else add_to_back(value); } print_list(); remove_from_front(); print_list(); remove_from_front(); print_list(); remove_from_front(); print_list(); return 0; } void add_to_back(int v) { struct node *new_node; new_node = (struct node *) malloc(sizeof(struct node)); if (new_node == NULL) { printf("Error: malloc failed in add_to_back\n"); exit(EXIT_FAILURE); } new_node->value = v; if (front == NULL) { front = new_node; //special case, empty list } else { struct node *cur; for (cur = front; cur->next != NULL; cur = cur->next) { ; //traverse list } cur->next = new_node; } } void remove_from_front() { if (front == NULL) return; //empty list struct node *cur = front; front = front->next; cur->next = NULL; free(cur); } void print_list() { struct node *cur; for (cur = front; cur != NULL; cur = cur->next) { printf("%d ", cur->value); } printf("\n"); }