Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You are asked to simulate the operations of a list. In one test case, there will be only one list. The operations are defined as

image text in transcribedimage text in transcribedimage text in transcribed

You are asked to simulate the operations of a list. In one test case, there will be only one list. The operations are defined as below. We will use the list {2, 10, 5} as an example to illustrate each operation. You can safely assume all operations are valid. Operations Description init sint> (e.g. init 3 7 17 8) Initialize a number list with the specified numbers, the first integer specifies the length of the list (e.g. {7, 17, 8}) insert Front (e.g. insert Front 8) Insert a number at the front of the list (e.g. {8, 2, 10, 5}) insertEnd (e.g. insertEnd 8) Insert a number at the end of the list (e.g. {2, 10, 5, 8}) insertAt (e.g. insertat 8 2) Insert a number (first int) at an index position (second int) (e.g. {2, 10, 8, 5}) delete (e.g. delete 10) Delete all nodes having the same value (e.g. {2,5}) deleteAt (e.g. deleteAt 2) Delete the specified node (e.g. {2, 10}) print (e.g. print) Print the integer list with space separating the numbers (e.g. 2 10 5) find_kth (e.g. find_kth 2) Print the specified node (e.g. 5) Your program should read the input from the file, and output the answer to another file. The first argument is the input file name, while the second argument is the output file name. Name your program as lab1-92.c. Input file: It contains many lines, and each line corresponds to one operation. Output file: Print the number based on the operations, print and find_kth. One line corresponds to one printing operation. Sample Input: init 5 1 2 1 2 1 insert Front 3 insert Front 3 insertEnd 3 print Sample Output: 3 3 1 2 1 2 1 3 Hint: The code below will be helpful in reading the file to EOF char command [20]; while (fscanf(fin, %s, command) > 0) { // Use if-else or switch-case to handle different commands } Hint: The code below will be helpful in determining the command if (strncmp(command, "init, 4) == 0) { // Code about "init } else if ... Hint: The code below will be helpful in clearing the character array, command memset(command, 0, sizeof(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

Data Mining Concepts And Techniques

Authors: Jiawei Han, Micheline Kamber, Jian Pei

3rd Edition

0123814790, 9780123814791

More Books

Students also viewed these Databases questions