I want to know that swapping is performed or not in the first steps of this example . when the the element 2 <=4 then the value of i is incremented and the i point to the 2 val in the example and also the j is pointed to the 2val means the oth index and then after swapping remain same because both the varible is pointed to same element ? .
And also want to know that why we set the pos of the i=s-1 ,we can set just i=s, and then check if its is smaller or not with pivot element , or we set the i=s-1 to because we have to perform the swap operation if the element is smaller to maintain the states for the swap function?? Please correct me if i am wrong?
Quick sort the logical behind the i variable and the swapping
Yes, swapping is done , u are correct in saying that both i and j are pointing to the 0th index and swap(a[0], a[0]) is performed in the first step.
This is basically because we are pre incrementing it before the swap operation if the element at j th index is smaller than pivot value.
If u were to start with i = s then we would have simply used post increment, both would have worked fine for us.