Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C, Write a program list that maintains and manipulates a linked list of integers according to instructions provided in a le. list takes a

In C, Write a program list that maintains and manipulates a linked list of integers according to instructions provided in a le. list takes a single argument, which is the path to a le containing the instructions. If the le does not exist, your program must print error and nothing else. list maintains a linked list containing zero or more integers, ordered from least to greatest. list will need to allocate space for new nodes as they are created using malloc; any allocated space should be deallocated using free before list terminates. It supports two operations on this list: 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. Input format Each line of the input le 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 i 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. Output format- Normal output for list is written on two lines. The rst line is an integer indicating the length of the linked list after all instructions are performed. The second line is zero or more integers separated by spaces indicating the content of the linked list. If the le given on the command line does not exist, list should print error and nothing else. Usage Assume three text les. The rst, file1.txt, is empty. The second, file2.txt, contains:

i 5

i 2

i 8

i 3

d 2 The third, file3.txt, contains: d 12

i 10

i 7

i 10

i 5

d 10 Assume also that there is no le file4.txt. With these assumptions

$ ./list file1.txt

0 $ ./list file2.txt

3

3 5 8

$ ./list file3.txt

2

5 7

$ ./list file4.txt

error

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

Students also viewed these Databases questions