Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please Help with following program, also the program should terminate by pressing Control + D (^D) Inputs and outputs: $ ./list i 5 1 :

Please Help with following program, also the program should terminate by pressing Control + D (^D)

Inputs and outputs:

$ ./list

i 5

1 : 5

d 3

1 : 5

i 3

2 : 3 5

i 500

3 : 3 5 500

d 5 2 : 3 500

^D

image text in transcribed

1.4 list: Linked lists Write a program list that maintains and manipulates a sorted linked list according to instructions received from standard input. The linked list is maintained in order, meaning that the items in the list are stored in increasing numeric order after every operation. Note that list will need to allocate space for new nodes as they are created, using malloc; any allocated space should be deallocated using free as soon as it is no longer needed. Note also that the list will not contain duplicate values. list supports two operations: insert n Adds an integer n to the list. If n is already present in the list, it does nothing. The instruction format is an i followed by a space and an integer n. delete n Removes an integer n from the list. If n is not present in the list, it does nothing. The instruction format is a d followed by a space and an integer n. After each command, list will print the length of the list followed by the contents of the list, in order from first (least) to last (greatest). list must halt once it reaches the end of standard input. Input format Each line of the input contains an instruction. Each line begins with a letter (either "I" or "d"), followed by a space, and then an integer. A line beginning with "" indicates that the integer should be inserted into the list. A line beginning with "d" indicates that the integer should be deleted from the list. Your program will not be tested with invalid input. You may choose to have list terminate in response to invalid input. Output format After performing each instruction, list will print a single line of text containing the length of the list, a colon, and the elements of the list in order, all separated by spaces. Usage Because list reads from standard input, you may test it by entering inputs line by line from the terminal. 1.4 list: Linked lists Write a program list that maintains and manipulates a sorted linked list according to instructions received from standard input. The linked list is maintained in order, meaning that the items in the list are stored in increasing numeric order after every operation. Note that list will need to allocate space for new nodes as they are created, using malloc; any allocated space should be deallocated using free as soon as it is no longer needed. Note also that the list will not contain duplicate values. list supports two operations: insert n Adds an integer n to the list. If n is already present in the list, it does nothing. The instruction format is an i followed by a space and an integer n. delete n Removes an integer n from the list. If n is not present in the list, it does nothing. The instruction format is a d followed by a space and an integer n. After each command, list will print the length of the list followed by the contents of the list, in order from first (least) to last (greatest). list must halt once it reaches the end of standard input. Input format Each line of the input contains an instruction. Each line begins with a letter (either "I" or "d"), followed by a space, and then an integer. A line beginning with "" indicates that the integer should be inserted into the list. A line beginning with "d" indicates that the integer should be deleted from the list. Your program will not be tested with invalid input. You may choose to have list terminate in response to invalid input. Output format After performing each instruction, list will print a single line of text containing the length of the list, a colon, and the elements of the list in order, all separated by spaces. Usage Because list reads from standard input, you may test it by entering inputs line by line from the terminal

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_2

Step: 3

blur-text-image_3

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

Database Management Systems Designing And Building Business Applications

Authors: Gerald V. Post

1st Edition

0072898933, 978-0072898934

More Books

Students also viewed these Databases questions

Question

In what ways can leaders create ethical organizations?

Answered: 1 week ago

Question

How can companies control the costs of each required benefit?

Answered: 1 week ago