Question
Below are the node_struct, link, list_struct and list as defined in class and in hw3: typedef struct node_struct * link; struct node_struct { int item;
Below are the node_struct, link, list_struct and list as defined in class and in hw3: typedef struct node_struct * link; struct node_struct { int item; link next; }; | typedef struct list_struct * list; struct list_struct { link first; int length; }; |
a) (15 pts) Write a function that swaps the first and last node in a list. If there are not enough nodes, it does not do anything to the list. You have to update the links yourself. DO NOT call any insert or remove functions to do any of the work for you. void swapFirstLast(list L) { b) (8 pts) Make a drawing of a list with 5 (five) nodes and show how the links are updated as done in class. Label each arrow update with the line number that did it. c) (3 pts) What is the complexity of your function? Justify your answer. (You can show to the side of the code) d) (4 pts) If your function fails or crashes for certain inputs, give those inputs and clearly indicate the line with the problem (use line numbers or write the test cases as a comment on that line of code).
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