#include #include struct node { int value; struct node *next; }; struct node *front; void add_to_front(int v); void remove_from_back(); 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_front(value); } print_list(); remove_from_back(); print_list(); remove_from_back(); print_list(); remove_from_back(); print_list(); return 0; } void add_to_front(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_front\n"); exit(EXIT_FAILURE); } new_node->value = v; new_node->next = front; front = new_node; } void remove_from_back() { if (front == NULL) return; //empty list struct node *cur, *prev; for (cur = front, prev = NULL; cur->next != NULL; prev = cur, cur = cur->next) ; //cur will point to last node of list if (prev == NULL) //special case where only one node front = front->next; //sets front to NULL else prev->next = cur->next; //sets prev->next to NULL free(cur); } void print_list() { struct node *cur; for (cur = front; cur != NULL; cur = cur->next) { printf("%d ", cur->value); } printf("\n"); }