The following C function rearranges the members of a single-linked list of integers that is passed as a parameter. The list of numbers 1, 2, 3, 4, 5, 6, and 7 in the specified order is passed to the function when it is called. How many components will move about in the list once the function is finished running?
I’m getting the answer as ‘2’ , but the given key is ‘6’ and the final list is “ 2, 1, 4, 3, 6, 5, 7 ”
Can anyone please help, what’s going wrong, thanks
@Souvik33 use precedence rule in line 20, it will be like:
q = (p ? (p --> next) : 0) Isn't it?
= has the lowest precedence here so it will be computed last.
The list after running the rearrange method will become 2 1 4 3 6 5 7 so 6 elements are not in their position.
q = (p ? (p --> next) : 0)
Thanks @Sunnidhya Roy for this you are right. 😊
Very good section to do silly mistake ↓↓
64.3k questions
77.9k answers
244k comments
80.0k users