Answered step by step
Verified Expert Solution
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
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started