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 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,50$ as an example to illustrate each operation. You can safely assume all operations are valid. \begin{tabular)(11/11) Whline Operations & Description Whline init (int> (e. g. init 37178 ) & Initialize a number list with the specified numbers, the first integer specifies the length of the list (e.g. $17,17,8\}$ ) hline insertFront (e.5. insertFront 8) & Insert a number at the front of the list (e.g. $1 {8,2,10,50$ ) hline insertEnd (e.g. insertEnd 8 ) & Insert a number at the end of the list (e.g. $ {2,10,5,8V)$) Thiine insertat (e.: insertat 8 2) & Insert a number (first int) at an index position (second int) (e.5. $2,10,8,50$) W Nhline delete (e. g. delete 16) & Delete all nodes having the same value (0.8. ${2,5V5 ) Whline deleteAt (e. 5. deleteAt 2) & Delete the specified node (e.g. $\{2,10\}$ ) Whline \end{tabular) \begin{tabular){111111 Whline print (e. g. print) & Print the integer list with space separating the numbers (e.g. 2 10 5) Whline find_kth (e... find_kth 2) & Print the specified node (e.g. 5) W Whline Vend tabular) 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 "labl-q2.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 $\begin{array}{111111) & 1 & 2 & 1 & 2 & 1\end{array}$ insertFront 3 insertFront 3 insertend 3 print Sample Output: $\begin{array}{11111111)3 & 3 & 1 & 2 & 1 & 2 & l\end{array}$ Hint: The code below will be helpful in reading the file to EOF char command[20]; while (fscanf(fin, cros", command) > > 0 ) N // 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)); SE.SD.023

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

Professional SQL Server 2012 Internals And Troubleshooting

Authors: Christian Bolton, Justin Langford

1st Edition

1118177657, 9781118177655

More Books

Students also viewed these Databases questions

Question

How do Excel Pivot Tables handle data from non OLAP databases?

Answered: 1 week ago