Skip to content

Commit bcd7141

Browse files
authored
Merge pull request larissalages#256 from ALaurinne/1-quick-sort
Add QuickSort in Dart
2 parents e4bf65e + 320f0eb commit bcd7141

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
void Quicksort(list, int leftElement, int rightElement) {
2+
int left = leftElement;
3+
int right = rightElement;
4+
int pivot = list[(leftElement + rightElement) ~/ 2];
5+
6+
while (left <= right) {
7+
while (list[left] < pivot) {
8+
left++;
9+
}
10+
11+
while (list[right] > pivot) {
12+
right--;
13+
}
14+
15+
if (left <= right) {
16+
int temp = list[left];
17+
list[left] = list[right];
18+
list[right] = temp;
19+
left++;
20+
right--;
21+
}
22+
}
23+
24+
if (leftElement < right) {
25+
Quicksort(list, leftElement, right);
26+
}
27+
28+
if (left < rightElement) {
29+
Quicksort(list, left, rightElement);
30+
}
31+
}

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Code | Test
3535
Code | Test
3636
------------ | -------------
3737
[Bubble Sort](https://github.com/larissalages/code_problems/blob/master/classical_algorithms/dart/BubbleSort.dart) | Missing tests
38+
[Quick Sort](https://github.com/larissalages/code_problems/blob/master/classical_algorithms/dart/QuickSort.dart) | Missing tests
3839

3940
### C++
4041
Code | Test

0 commit comments

Comments
 (0)