Skip to content

Commit 623a75c

Browse files
authored
Merge pull request #12 from berezuev/patch-1
Use $size instead of counting on each iteration in QuickSort
2 parents 5ab104d + 291a674 commit 623a75c

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/Algorithm/Sorting/QuickSort.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*
66
* Copyright (c) 2018 Dogan Ucar
77
*
8+
* @author Alexey Berezuev <alexey@berezuev.ru>
9+
*
810
* Permission is hereby granted, free of charge, to any person obtaining a copy
911
* of this software and associated documentation files (the "Software"), to deal
1012
* in the Software without restriction, including without limitation the rights
@@ -51,7 +53,7 @@ public function sort(array $array): array {
5153
$pivot = $array[0];
5254
$left = $right = [];
5355

54-
for ($i = 1; $i < count($array); $i++) {
56+
for ($i = 1; $i < $size; $i++) {
5557
if (Comparator::lessThan($array[$i], $pivot)) {
5658
$left[] = $array[$i];
5759
} else {

0 commit comments

Comments
 (0)