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