Answered step by step
Verified Expert Solution
Question
1 Approved Answer
P14. Write a function that takes as argument a node p, and swaps the two nodes following p if the data in the first one
P14. Write a function that takes as argument a node p, and swaps the two nodes following p if the data in the first one is larger than that of the second one. You must readjust the links, not copy the data from one node into the other. No credit given otherwise. For example if p ->6->3->2> the two nodes following p have data 6 and 3 and since 6>3 the nodes will be swapped (keep in mind that you must readjust the links, not just swap the values 3 and 6). Ifp ->3.>2. the function will not swap: p->3->6>2. typedef struct nodelinki Assume the class provided struct node [ representation of nodes and links: int item; link next; )i a) The function does not crash (for pointer errors or otherwise). These points are only given if the program is also correct. b) Draw a picture of what happens with the links when you swap the nodes. Use line numbers (or code segments) to indicate on the picture what line of your code produces those changes. c) Write the function (Do not use anything that would bypass working with the links.)
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