Starting from:
$30

$24

Timed Lab 5: C Solution

Please take the time to read the entire document before starting the assignment. It is your responsibility to follow the instructions and rules.







Timed Lab Rules - Please Read



1.1 General Rules




You are allowed to submit this timed lab starting at the moment the assignment is released, until you are checked o by your TA as you leave the recitation classroom. Gradescope submissions will remain open until 7:15 pm - but you are not allowed to submit after you leave the recitation classroom under any circumstances. Submitting or resubmitting the assignment after you leave the classroom is a violation of the honor code - doing so will automatically incur a zero on the assignment and might be referred to the O ce of Student Integrity.



Make sure to give your TA your Buzzcard before beginning the Timed Lab, and to pick it up and get checked o before you leave. Students who leave the recitation classroom without getting checked o will receive a zero.



Although you may ask TAs for clari cation, you are ultimately responsible for what you submit. The information provided in this Timed Lab document takes precedence. If in doubt, please make sure to indicate any con icting information to your TAs.



Resources you are allowed to use during the timed lab:



Assignment les




Previous homework and lab submissions Your mind




Blank paper for scratch work (please ask for permission from your TAs if you want to take paper from your bag during the Timed Lab)




Resources you are NOT allowed to use:



The Internet (except for submissions)




Any resources that are not given in the assignment




Textbook or notes on paper or saved on your computer Email/messaging




Contact in any form with any other person besides TAs Any compiler that outputs LC3 code




Before you start, make sure to close every application on your computer. Banned resources, if found to be open during the Timed Lab period, will be considered a violation of the Timed Lab rules.



We reserve the right to monitor the classroom during the Timed Lab period using cameras, packet capture software, and other means.



1.2 Submission Rules




Follow the guidelines under the Deliverables section.



You are also responsible for ensuring that what you turned in is what you meant to turn in. After submitting you should be sure to download your submission into a brand new folder and test if it works. No excuses if you submit the wrong les, what you turn in is what we grade. In addition, your assignment must be turned in via Gradescope.


Do not submit links to les. We will not grade assignments submitted this way as it is easy to change the les after the submission period ends.



1.3 Is collaboration allowed?




Absolutely NOT. No collaboration is allowed for timed labs.







Overview



2.1 Description




In this timed lab, you’ll be writing two functions which will act on a linked list of pokemon structs. The rst of these, copy_list(), takes in a pointer to a list and returns a pointer to a \deep" copy of this list, with all dynamically-allocated data duplicated. The second, destroy(), takes in a pointer to a list and destroys this list, freeing all dynamically-allocated memory associated with it.







Instructions



You have been given one C le - tl5.c - in which you should complete the copy_list() and destroy() functions according to the comments.




You should not modify any other les. Doing so may result in point deductions. You should also not modify the #include statements, nor add any more. You are also not allowed to add any global variables.




3.1 Writing copy_list()




The function copy_list() takes in one argument, a pointer to struct list, and returns a pointer to a new struct list. The list returned should be identical to the list passed in, but should be an entirely di erent list|that is, the list struct, all pokemon structs, and any dynamic attributes of the pokemon struct will be copied over into new dynamically allocated memory. This is known as a deep copy.




NOTE! When you make this copy, you should note every place you have allocated memory...because when you destroy a list, you’ll have to free all the dynamically allocated memory.




BONUS NOTE! If any memory allocation failures occur, you must destroy the entire list and free all dynamically allocated memory before returning NULL. This means that your copy_list() function may depend on your destroy() function!




The following diagram highlights the nature of a deep copy. Notice that every piece of data is duplicated. The diagram shows the state after the following code is executed successfully, without memory allocation errors:




//pre-condition: listToCopy points to
a
valid list, populated with
data.


struct list *newList = copy_list(listToCopy);




//post-condition: the list pointed to
by listToCopy is not altered
in any way,
//
and the list pointed to
by newList is in the state
shown
below.








struct list *listToCopy







struct pokemon *starter_pokemon




struct list





struct pokemon *evolve




27
"Cubone"


char *type




struct pokemon



struct pokemon *evolve








28
"Marowak"


char *type




struct pokemon



struct list *newList







struct pokemon *starter_pokemon




struct list





struct pokemon *evolve




27
"Cubone"


char *type




struct pokemon



struct pokemon *evolve








28
"Marowak"


char *type




struct pokemon


More products