Skip to content

Commit 916592f

Browse files
committed
select sort is OK & add shell sort
1 parent 5462b0b commit 916592f

File tree

9 files changed

+17
-62
lines changed

9 files changed

+17
-62
lines changed

.TestSort.php.swp

-12 KB
Binary file not shown.

.test.php.swp

-12 KB
Binary file not shown.

Graphic/.GraALG.php.swp

-12 KB
Binary file not shown.

Sort/.BubbleSort.php.swp

-12 KB
Binary file not shown.

Sort/.StraightInsertionSort.php.swp

-12 KB
Binary file not shown.

Sort/ShellSort.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace Sort;
4+
5+
class ShellSort
6+
{
7+
8+
}

Sort/StraightInsertionSort.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@ public function __construct($array)
1414
public function insertSort()
1515
{
1616
$length = count($this->array);
17-
for ($i = 1; $i < $length; $i++) {
18-
$tmp = $this->array[$i];
19-
for ($j = $i - 1;$this->array[$j] > $tmp; $j--) {
20-
$this->array[$j+1] = $this->array[$j];
17+
self::printArray($this->array);
18+
for ($i = 1;$i < $length; $i++) {
19+
if ($this->array[$i - 1] > $this->array[$i]) {
20+
$tmp = $this->array[$i];
21+
for ($j = $i - 1; $this->array[$j] > $tmp && $j >= 0; $j--) {
22+
$this->array[$j+1] = $this->array[$j];
23+
}
24+
$this->array[$j + 1] = $tmp;
25+
self::printArray($this->array);
2126
}
22-
$this->array[$j] = $tmp;
23-
self::printArray($this->array);
2427
}
2528
}
2629

index.html

Lines changed: 0 additions & 8 deletions
This file was deleted.

test.php

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)