September Morn Update
This commit is contained in:
parent
4e2d22a71d
commit
aac6731f2c
6856 changed files with 141342 additions and 21127 deletions
|
|
@ -1,50 +1,50 @@
|
|||
import extensions.
|
||||
import system'math.
|
||||
import system'routines.
|
||||
import extensions;
|
||||
import system'math;
|
||||
import system'routines;
|
||||
|
||||
extension $op
|
||||
extension op
|
||||
{
|
||||
cocktailSort
|
||||
[
|
||||
var list := self clone.
|
||||
cocktailSort()
|
||||
{
|
||||
var list := self.clone();
|
||||
|
||||
bool swapped := true.
|
||||
bool swapped := true;
|
||||
while(swapped)
|
||||
[
|
||||
swapped := false.
|
||||
{
|
||||
swapped := false;
|
||||
|
||||
0 to(list length - 2) do(:i)
|
||||
[
|
||||
for(int i := 0, i <= list.Length - 2, i += 1)
|
||||
{
|
||||
if (list[i]>list[i+1])
|
||||
[
|
||||
list exchange(i,i+1).
|
||||
swapped := true.
|
||||
]
|
||||
].
|
||||
{
|
||||
list.exchange(i,i+1);
|
||||
swapped := true
|
||||
}
|
||||
};
|
||||
ifnot (swapped)
|
||||
[
|
||||
{
|
||||
^ list
|
||||
].
|
||||
swapped := false.
|
||||
};
|
||||
swapped := false;
|
||||
|
||||
(list length - 2) to(0) do(:i)
|
||||
[
|
||||
for(int i := list.Length - 2, i >= 0, i -= 1)
|
||||
{
|
||||
if (list[i]>list[i+1])
|
||||
[
|
||||
list exchange(i,i+1).
|
||||
swapped := true.
|
||||
]
|
||||
].
|
||||
].
|
||||
{
|
||||
list.exchange(i,i+1);
|
||||
swapped := true
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
^ list
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
program =
|
||||
[
|
||||
var list := (3, 5, 1, 9, 7, 6, 8, 2, 4 ).
|
||||
public program()
|
||||
{
|
||||
var list := new int[]{3, 5, 1, 9, 7, 6, 8, 2, 4 };
|
||||
|
||||
console printLine("before:", list).
|
||||
console printLine("after :", list cocktailSort).
|
||||
].
|
||||
console.printLine("before:", list.asEnumerable());
|
||||
console.printLine("after :", list.cocktailSort().asEnumerable())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue