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
> print
3 5
> insert
enter a number: 4
> print
3 4 5
> insert
enter a number: 4
> print
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) );
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.