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 file. list takes a

In C.

Write a program list that maintains and manipulates a linked list of integers according to instructions provided in a file. list takes a single argument, which is the path to a file containing the instructions. If the file 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 file 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 first 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 file given on the command line does not exist, list should print error and nothing else.

Usage Assume three text files. The first, 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 file 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

Recommended Textbook for

IBM Db2 11 1 Certification Guide Explore Techniques To Master Database Programming And Administration Tasks In IBM Db2

Authors: Mohankumar Saraswatipura ,Robert Collins

1st Edition

1788626915, 978-1788626910

More Books

Students also viewed these Databases questions

Question

1.The difference between climate and weather?

Answered: 1 week ago

Question

1. What is Fog ?

Answered: 1 week ago

Question

How water vapour forms ?

Answered: 1 week ago

Question

What is Entrepreneur?

Answered: 1 week ago

Question

Which period is known as the chalolithic age ?

Answered: 1 week ago

Question

8. Do the organizations fringe benefits reflect diversity?

Answered: 1 week ago

Question

7. Do the organizations social activities reflect diversity?

Answered: 1 week ago