Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

THIS IS FOR C PROGRAMMING. Create a program to follow simple linked list instructions ( cf. the table below). The program will read in the

THIS IS FOR C PROGRAMMING. Create a program to follow simple linked list instructions (cf. the table below). The program will read in the lines of a data file containing some sequence of the instructions.

Instruction

Code

Explanation

Error Checking

Initialize

I value

Initialize and empty linked list. value is ignored.

Report an error and exit for second Initialize (i.e. cant initialize more than once).

Add Beginning

B value

Add a node at the beginning of the list with value value.

N.A.

Add End

C value

Add a node at the end of the list with value value.

N.A.

Remove Beginning

R value

Remove the node at the beginning of the list, and print its value. value is ignored.

Report an error and exit if the list is empty.

Remove End

S value

Remove the node at the end of the list, and print its value. value is ignored.

Report an error and exit if the list is empty.

Traverse

T value

Print out all of the values in the nodes in the list, in order. value is ignored.

N.A.

Exit

X value

Exit the program. value is ignored.

N.A.

The program should operate as follows: 1. Start, and prompt the user for the name of the data file from which to read the instructions.

2. Open the data file and read in the instructions, line by line

3. Follow the instructions on each line, being sure to check for errors in the applicable

cases. The values in the add instructions are integers.

4. The program should exit either when the Exit (X) instruction is seen, or the end of

the file is detected.

Example:

Assume you had a data file, m4input2.dat with the following contents:

I 0

B 1

B 2

C 4

C 6

T 0

R 0

S 0

T 0

X 0

B 7

B 8

B 9

If you ran the program using that file, the trace of the run would look something like this:

Please enter the path and name for the input file: m4input2.dat Using the file m4input2.dat for input.

Processing I The list has been initialized.

Processing B Added the value 1 to a node at

Processing B Added the value 2 to a node at

Processing C Added the value 4 to a node at

Processing C Added the value 6 to a node at

the beginning of the list. the beginning of the list. the end of the list. the end of the list.

Processing T Traversing the list and it contains the following values: 2 1 4 6

CSI/CEN 213 v 2017 11 29 Fall 2017

Processing R Removed the node with value 0 from the beginning of the list.

Processing S Removed the node with value 0 from the end of the list.

Processing T Traversing the list and it contains the following values: 1 4

Processing X Exiting...

Note that the program ignores several lines of input after the X (exit) command.

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

Database Design And SQL For DB2

Authors: James Cooper

1st Edition

1583473572, 978-1583473573

More Books

Students also viewed these Databases questions

Question

Describe Table Structures in RDMSs.

Answered: 1 week ago