This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def partition(array, start, end): | |
| pivot = array[end] | |
| partition_index = start | |
| print(pivot, partition_index) | |
| for itr in range(start, end): | |
| if array[itr] < pivot: | |
| array[partition_index], array[itr] = array[itr], array[partition_index] | |
| partition_index += 1 | |
| print(array) | |
| array[partition_index], array[end] = array[end], array[partition_index] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class QSort{ | |
| static void printArray(int[] arr, int size) | |
| { | |
| for(int i = 0; i < size; i++) | |
| System.out.print(arr[i] + " "); | |
| System.out.println(); | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function partition(array, low, high){ | |
| var pivot = array[high]; | |
| var partition_index = low; | |
| var temp; | |
| for (var itr=low; itr<high; itr++){ | |
| if (array[itr]<pivot){ | |
| temp = array[itr]; | |
| array[itr] = array[partition_index]; | |
| array[partition_index] = temp; | |
| partition_index += 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def partition(array, start, end): | |
| pivot = array[end] | |
| partition_index = start | |
| for itr in range(start, end): | |
| if array[itr] < pivot: | |
| array[partition_index], array[itr] = array[itr], array[partition_index] | |
| partition_index += 1 | |
| array[partition_index], array[end] = array[end], array[partition_index] | |
| return partition_index |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class QSort{ | |
| static void printArray(int[] arr, int size) | |
| { | |
| for(int i = 0; i < size; i++) | |
| System.out.print(arr[i] + " "); | |
| System.out.println(); | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function partition(array, low, high){ | |
| var pivot = array[high]; | |
| var partition_index = low; | |
| var temp; | |
| for (var itr=low; itr<high; itr++){ | |
| if (array[itr]<pivot){ | |
| temp = array[itr]; | |
| array[itr] = array[partition_index]; | |
| array[partition_index] = temp; | |
| partition_index += 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def find_max_min(array): | |
| max_val, min_val = None, None | |
| if len(array) == 1: | |
| max_val = min_val = array[0] | |
| elif array: | |
| max_val, min_val = (array[0], array[1]) if array[0] > array[1] else (array[1], array[0]) | |
| for itr in array[2:]: | |
| if itr > max_val: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class MinMax { | |
| int min; | |
| int max; | |
| MinMax(int min, int max) | |
| { | |
| min = min; | |
| max = max; | |
| } | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function find_max_min(array){ | |
| var max_val; | |
| var min_val; | |
| if (array.length == 1){ | |
| max_val = array[0]; | |
| min_val = array[0]; | |
| } | |
| else if(array.length > 1){ | |
| if (array[0] > array[1]){ | |
| max_val = array[0]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def find_min_max(array, low, high): | |
| arr_min = array[low] | |
| arr_max = array[high] | |
| if low == high: | |
| arr_max = arr_min = array[low] | |
| elif low == high + 1: | |
| max_val, min_val = (array[0], array[1]) if array[0] > array[1] else (array[1], array[0]) | |
| else: |