Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,67 @@
import extensions;
extension op
{
pancakeSort()
{
var list := self.clone();
int i := list.Length;
if (i < 2) { ^ self };
while (i > 1)
{
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, i)
};
i -= 1
};
^ list
}
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;
i += 1;
count -= 1
}
}
}
public program()
{
var list := new int[]{6, 7, 8, 9, 2, 5, 3, 4, 1};
console.printLine("before:", list.asEnumerable());
console.printLine("after :", list.pancakeSort().asEnumerable())
}