Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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) );

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Securing SQL Server Protecting Your Database From Attackers

Authors: Denny Cherry

3rd Edition

0128012757, 978-0128012758

More Books

Students also viewed these Databases questions