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
| 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
| 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
| 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
| 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
| 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
| 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
| var arr = [1, 2, 3, 4, 5]; | |
| arr.reverse() | |
| console.log(arr) |
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
| import java.util.*; | |
| public class Main { | |
| /*function reverses the elements of the array*/ | |
| static void reverse(Integer myArray[]) | |
| { | |
| Collections.reverse(Arrays.asList(myArray)); | |
| System.out.println("Reversed Array:" + Arrays.asList(myArray)); | |
| } |
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
| arr = [1, 2, 3, 4, 5] | |
| arr.reverse() | |
| print(arr) |