Question
Problem Description: Write a C program that implements a linked list. You have to implement only two operations: insert, that adds an element into the
Problem Description:
Write a C program that implements a 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.
Sample Output:
>Operation to be performed (Insert, Print or Exit) insert
enter the data item: 3
> Operation to be performed (Insert, Print or Exit) insert
enter a number: 5
> Operation to be performed (Insert, Print or Exit) print
3 5
> Operation to be performed (Insert, Print or Exit) insert
enter a number: 7
> Operation to be performed (Insert, Print or Exit) print
3 5 7
> Operation to be performed (Insert, Print or Exit) print
3 5 7
> Operation to be performed (Insert, Print or Exit) remove
Error: unknown request 'remove'
> Operation to be performed (Insert, Print or Exit) exit
The bold italic text in the example above represents the user input.
Requirements: 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) );
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started