September Morn Update
This commit is contained in:
parent
4e2d22a71d
commit
aac6731f2c
6856 changed files with 141342 additions and 21127 deletions
|
|
@ -1,66 +1,67 @@
|
|||
import extensions.
|
||||
import extensions;
|
||||
|
||||
extension $op
|
||||
extension op
|
||||
{
|
||||
pancakeSort
|
||||
[
|
||||
var list := self clone.
|
||||
pancakeSort()
|
||||
{
|
||||
var list := self.clone();
|
||||
|
||||
int i := list length.
|
||||
int i := list.Length;
|
||||
|
||||
if (i < 2) [ ^ self ].
|
||||
if (i < 2) { ^ self };
|
||||
|
||||
while (i > 1)
|
||||
[
|
||||
int max_num_pos := 0.
|
||||
int a := 0.
|
||||
{
|
||||
int max_num_pos := 0;
|
||||
int a := 0;
|
||||
while (a < i)
|
||||
[
|
||||
{
|
||||
if (list[a] > list[max_num_pos])
|
||||
[
|
||||
{
|
||||
max_num_pos := a
|
||||
].
|
||||
};
|
||||
|
||||
a += 1
|
||||
].
|
||||
};
|
||||
|
||||
if (max_num_pos == i - 1)
|
||||
[
|
||||
];
|
||||
[
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
if (max_num_pos > 0)
|
||||
[
|
||||
list flip(list length, max_num_pos + 1)
|
||||
].
|
||||
{
|
||||
list.flip(list.Length, max_num_pos + 1)
|
||||
};
|
||||
|
||||
list flip(list length, i)
|
||||
].
|
||||
list.flip(list.Length, i)
|
||||
};
|
||||
i -= 1
|
||||
].
|
||||
};
|
||||
|
||||
^ list
|
||||
]
|
||||
}
|
||||
|
||||
flip(IntNumber length, IntNumber num)
|
||||
[
|
||||
int i := 0.
|
||||
int count := num - 1.
|
||||
flip(int length, int num)
|
||||
{
|
||||
int i := 0;
|
||||
int count := num - 1;
|
||||
while (i < count)
|
||||
[
|
||||
var swap := self[i].
|
||||
self[i] := self[count].
|
||||
self[count] := swap.
|
||||
{
|
||||
var swap := self[i];
|
||||
self[i] := self[count];
|
||||
self[count] := swap;
|
||||
|
||||
i += 1.
|
||||
i += 1;
|
||||
count -= 1
|
||||
]
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
program =
|
||||
[
|
||||
var list := (6, 7, 8, 9, 2, 5, 3, 4, 1).
|
||||
public program()
|
||||
{
|
||||
var list := new int[]{6, 7, 8, 9, 2, 5, 3, 4, 1};
|
||||
|
||||
console printLine("before:", list).
|
||||
console printLine("after :", list pancakeSort).
|
||||
].
|
||||
console.printLine("before:", list.asEnumerable());
|
||||
console.printLine("after :", list.pancakeSort().asEnumerable())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue