#include #include struct node { int value; struct node *next; }; typedef struct node Node; int main() { int input; Node *list, *tmp; list = tmp = NULL; while (input != -1) { printf("Enter a value(-1 to end): "); scanf("%d", &input); if (input != -1) { if (list == NULL) { list = tmp = (Node *) malloc(sizeof(Node)); tmp->next = NULL; list->value = input; } else { tmp->next = (Node *) malloc(sizeof(Node)); tmp->next->next = NULL; tmp->next->value = input; tmp = tmp->next; } } } tmp = list; input = 0; while (tmp != NULL) { printf("[%d] %d ->", input, tmp->value); tmp = tmp->next; input = input + 1; } printf("NULL\n"); //insert into list printf("Which node would you like to insert before?"); scanf("%d", &input); tmp = list; int seeker; tmp = list; Node *tmp2 = NULL; for (seeker = 0; seeker < input - 1; seeker++) { tmp = tmp->next; } if (input == 0) { printf(" enter value for new node "); scanf("%d", &input); tmp2 = (Node *) malloc(sizeof(Node)); tmp2->value = input; tmp2->next = NULL; tmp2->next = tmp; list = tmp2; } else { printf("Enter a value to insert: "); scanf("%d", &input); tmp2 = (Node *) malloc(sizeof(Node)); tmp2->value = input; tmp2->next = tmp->next; tmp->next = tmp2; } tmp = list; input = 0; tmp = list; printf("Which node would you like to insert after?"); scanf("%d", &input); tmp = list; seeker; tmp = list; Node *tmp3 = NULL; for (seeker = 0; seeker < input; seeker++) { tmp = tmp->next; } if (input == 0) { printf(" enter value for new node "); scanf("%d", &input); tmp3 = (Node *) malloc(sizeof(Node)); tmp3->value = input; tmp3->next = NULL; tmp3->next = tmp; list = tmp3; } else { printf("Enter a value to insert: "); scanf("%d", &input); tmp3 = (Node *) malloc(sizeof(Node)); tmp3->value = input; tmp3->next = tmp->next; tmp->next = tmp3; } tmp = list; input = 0; while (tmp != NULL) { printf("[%d] %d ->", input, tmp->value); tmp = tmp->next; input = input + 1; } printf("NULL\n"); return (0); }