Function is stuck in some self infinite loop

programming
Tags: #<Tag:0x00007f18273be020>

#1

The function defined is getting stuck in some sort of infinite loop by itself. Just to try i put in a cout statement and a return 0; And it kept on printing the cout statement until stopping. Is anyone else getting such an issue?


#2

Yes, I am also getting the same problem. If you print something in the function it will print it many times makes difficult to debug the function, But if you return something it will work perfectly fine. :grinning:


#3

check the condition where the first/last element is the pivot element the condition should be something like this , for direction to go to find the pivot element.

if(a[l] > a[m])
u=(m-1+n)%n;
else
l=(m+1)%n;

not this ,

if(a[l] > a[m])
u=(m-1+n)%n;
else if(a[u] < a[m])
l=(m+1)%n;