, ,
3
:
-
2 .
-
min ( max, ) , 1 ( +1 -1
-
.
O (N). - O (N)
:
function Sort(a)
{
startPointer = 0;
endPointer = a.length-1;
result = new Array of size a.length
while (startPointer <= endPointer)
{
var newValue;
if (a[startPointer] < a[endPointer])
{
newValue = a[startPointer];
startPointer +1
}
else
{
newValue = a[endPointer];
endPointer -1
}
result[a.length - startPointer - endPointer] = newValue;
}
return result;
}
:
usde partil .
(10 11) {10, 12, 14, 16, 15, 13, 11}
(12 11) 12 11 {10, 11, 14, 16, 15, 13, 12}
(14 12) 14 12 {10, 11, 12, 16, 15, 13, 14}// 14 13, .
{10, 11, 12} {16, 15, 13, 14} (N twicely)
: O (N) + (N/2) + O (N/4) +... O (N)
:
+5