-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
175 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<configuration> | ||
<platform key="Win_x86"> | ||
<project> | ||
<output>..\..\lib60</output> | ||
</project> | ||
</platform> | ||
<platform key="Win_x64"> | ||
<project> | ||
<output>..\..\lib60_64</output> | ||
</project> | ||
</platform> | ||
<project> | ||
<namespace>algorithms</namespace> | ||
<template>lib60</template> | ||
</project> | ||
<manifest> | ||
<name>ELENA Algorithms Library</name> | ||
<version>6.0.0</version> | ||
<author>Aleksey Rakov</author> | ||
</manifest> | ||
<files> | ||
<module> | ||
<include>quicksort.l</include> | ||
<include>sort_extensions.l</include> | ||
</module> | ||
</files> | ||
</configuration> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import system'routines; | ||
import system'collections; | ||
|
||
const int MAX_LEVELS = 64; | ||
|
||
public singleton QuickSortAlgorithm | ||
{ | ||
sort(SortingAgent source, int start, int length, Func2 compf) | ||
{ | ||
int beg[MAX_LEVELS]; | ||
int end[MAX_LEVELS]; | ||
|
||
beg[0] := start; | ||
end[0] := length; | ||
|
||
int i := 0; | ||
while (i >= 0) { | ||
int L := beg[i]; | ||
int R := end[i]; | ||
if (R > L + 1) { | ||
R--; | ||
|
||
var piv := source[L]; | ||
while (L < R) { | ||
while ((!compf(source[R], piv)) && L < R) | ||
R--; | ||
|
||
if (L < R) { | ||
source[L] := source[R]; | ||
L++; | ||
}; | ||
|
||
while (compf(source[L], piv) && L < R) | ||
L++; | ||
|
||
if (L < R) { | ||
source[R] := source[L]; | ||
R--; | ||
} | ||
}; | ||
source[L] := piv; | ||
if (L - beg[i] > end[i] - R) { | ||
beg[i + 1] := L + 1; | ||
end[i + 1] := end[i]; | ||
end[i] := L; | ||
i++; | ||
} | ||
else { | ||
beg[i + 1] := beg[i]; | ||
end[i + 1] := L; | ||
beg[i] := L + 1; | ||
i++; | ||
}; | ||
} | ||
else | ||
{ | ||
i--; | ||
} | ||
} | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import system'collections; | ||
import system'routines; | ||
|
||
public extension quickSortOp : Indexable | ||
{ | ||
quickSort(int length, Func2 compf) | ||
{ | ||
QuickSortAlgorithm.sort(new IndexerSortingAgent(self), 0, length, compf); | ||
} | ||
|
||
quickSort(int length) | ||
= self.quickSort(length, ifOrdered); | ||
} | ||
|
||
public extension quickSortOp2 : ArrayList | ||
{ | ||
quickSort(Func2 compf) | ||
{ | ||
QuickSortAlgorithm.sort(new IndexerSortingAgent(self), 0, self.Length, compf); | ||
} | ||
|
||
quickSort() | ||
{ | ||
QuickSortAlgorithm.sort(new IndexerSortingAgent(self), 0, self.Length, ifOrdered); | ||
} | ||
} | ||
|
||
public extension quickSortOp3 | ||
{ | ||
quickSort(Func2 compf) | ||
{ | ||
QuickSortAlgorithm.sort(new IndexerSortingAgent(self), 0, self.Length, compf); | ||
} | ||
|
||
quickSort() | ||
{ | ||
QuickSortAlgorithm.sort(new IndexerSortingAgent(self), 0, self.Length, ifOrdered); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,8 @@ public interface SortingAgent | |
} | ||
|
||
abstract at(int index); | ||
|
||
abstract setAt(int index, object value); | ||
|
||
abstract exchange(int i, int j); | ||
} | ||
|
@@ -34,6 +36,11 @@ public sealed ArraySortingAgent : SortingAgent | |
at(int index) | ||
= a[index]; | ||
|
||
setAt(int index, object value) | ||
{ | ||
a[index] := value; | ||
} | ||
|
||
exchange(int i, int j) | ||
{ | ||
var tmp := a[i]; | ||
|
@@ -71,6 +78,13 @@ public sealed IndexerSortingAgent : SortingAgent | |
|
||
^ *a | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
arakov
Author
Member
|
||
} | ||
|
||
setAt(int index, object value) | ||
{ | ||
a.Index := index; | ||
|
||
a.Value := value | ||
} | ||
|
||
exchange(int i, int j) | ||
{ | ||
|
This file contains 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
Is this like returning a value from a pointer?