Problem: Write a C program that implements a sorted linked list. You have to implement only two operations: insert, that adds an element into the list, and print that prints the entire list.
The program prompts the user to enter one of the following three requests: insert, print, or exit. insert lets the user add a number to the list, print prints the list, and exit terminates the program. For other requests the program displays an error message.
Below is a sample run of the program.
> insert
enter a number: 3
> insert
enter a number: 5
3 5
> insert
enter a number: 4
3 4 5
> insert
enter a number: 4
3 4 4 5
> remove
Error: unknown request 'remove'
> exit
The bold italic text in the example above represents the user input.
Organization: You have to follow the user interface requirements illustrated in the above example. You must also use structures to store each element of the linked list. Write separate functions for insert and print. You also need to create each node in the list using the C library function malloc as shown in the example below.
For example, if your structure is defined as
struct int_node
{
int node;
struct int_node *next;
};
A single node can be created dynamically as shown below:
struct int_node *node;
node = (struct int_node *) malloc( sizeof(struct int_node) );