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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!