September Morn Update

This commit is contained in:
Ingy döt Net 2019-09-12 10:33:56 -07:00
parent 4e2d22a71d
commit aac6731f2c
6856 changed files with 141342 additions and 21127 deletions

View file

@ -1,48 +1,49 @@
import extensions.
import system'routines.
import system'collections.
import extensions;
import system'routines;
import system'collections;
extension $op
extension op
{
quickSort
[
if (self isEmpty) [ ^ self ].
quickSort()
{
if (self.isEmpty()) { ^ self };
var pivot := self[0].
var pivot := self[0];
array_list less := ArrayList new.
array_list pivotList := ArrayList new.
array_list more := ArrayList new.
auto less := new ArrayList();
auto pivotList := new ArrayList();
auto more := new ArrayList();
self forEach(:item)
[
self.forEach:(item)
{
if (item < pivot)
[
less append(item)
];
if (item > pivot)
[
more append(item)
];
[
pivotList append(item)
]
].
{
less.append(item)
}
else if (item > pivot)
{
more.append(item)
}
else
{
pivotList.append(item)
}
};
less := less quickSort.
more := more quickSort.
less := less.quickSort();
more := more.quickSort();
less appendRange(pivotList).
less appendRange(more).
less.appendRange(pivotList);
less.appendRange(more);
^ less
]
}
}
program =
[
var list := (3, 14, 1, 5, 9, 2, 6, 3).
public program()
{
var list := new int[]{3, 14, 1, 5, 9, 2, 6, 3};
console printLine("before:", list).
console printLine("after :", list quickSort).
].
console.printLine("before:", list.asEnumerable());
console.printLine("after :", list.quickSort().asEnumerable());
}