1.alternate Sorting
1.alternate Sorting
Alternate Sorting
int lo = 0;
int hi = arr_size - 1;
switch (a[mid])
case 0:
//swap(low,mid)
temp = a[lo];
a[lo] = a[mid];
a[mid] = temp;
lo++;
mid++;
break;
case 1:
mid++;
break;
case 2:
//swap(mid,high)
temp = a[mid];
a[mid] = a[hi];
a[hi] = temp;
hi--;
break;
default:
mid++;
int i;
System.out.print(arr[i]+" ");
System.out.println("");
sort012(arr, arr_size);
printArray(arr, arr_size);
}
4.Kadanes Algorithm
Time Complexity:O(n)
Here we do s=i+1 bcos there is no hope that we will find greater element before i.So we extend I
to next position