| Прокодка раунд 1 |
| 1 | function SomeFunc(List) { if (List.length <= 1) { } return List; } const pivot = List[List.length - 1]; const leftList = []; const rightList = []; for (let i = 0; i <= List.length - 1; i++) { if (List[i] < pivot) { leftList.push(List[i]); } else { rightList.push(List[i]) } } return [...SomeFunc(leftList), pivot, ...SomeFunc(rightList)]; } |
| 2 | procedure SomeFunc( L, R : Integer ); var i,j,x,y : integer; begin i := l; j := r; x := a[(l+r) div 2]; repeat while (A[i] < x) do inc(i); while (x < A[j]) do dec(j); if ( i <= j ) then begin y:=A[i]; a[i]:=a[j]; a[j]:=y; inc(i); dec(j); end; until (i > j); if (l < j) then SomeFunc(l,j); if (i < r) then SomeFunc(i,r); end; |
| 3 | class SomeFunc { public static void SomeFunc(double[] arr, long first, long last) { double p = arr[(last - first)/2 + first]; double temp; long i = first, j = last; while(i p && j >= first) --j; if(i first) SomeFunc(arr, first, j); if(i key"); System.Console.ReadLine(); } } |
| 4 | def someFunc(nums, fst, lst): if fst >= lst: return i, j = fst, lst pivot = nums[random.randint(fst, lst)] while i <= j: while nums[i] < pivot: i += 1 while nums[j] > pivot: j -= 1 if i <= j: nums[i], nums[j] = nums[j], nums[i] i, j = i + 1, j - 1 someFunc(nums, fst, j) someFunc(nums, i, lst) |
| 5 | function someFunc(&$arr, $low, $high) { $i = $low; $j = $high; $middle = $arr[ ( $low + $high ) / 2 ]; do { while($arr[$i] < $middle) ++$i; while($arr[$j] > $middle) —$j; if($i <= $j){ $temp = $arr[$i]; $arr[$i] = $arr[$j]; $arr[$j] = $temp; $i++; $j--; } } while($i < $j); if($low < $j){ someFunc($arr, $low, $j); } if($i < $high){ someFunc($arr, $i, $high); } } |
Комментарии