in Programming in C
748 views
1 vote
1 vote

 

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?

in Programming in C
748 views

1 Answer

1 vote
1 vote

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

 

2 Comments

@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.

2
2

q = (p ? (p --> next) : 0) 

Thanks @Sunnidhya Roy for this you are right. 😊

Very good section to do silly mistake ↓↓

 

2
2

Related questions