Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Few fixes + beginning of the sorting example

  • Loading branch information...
commit 3f65028327073f78532013a5d8c4f4c74c99c6a7 1 parent 695c3a3
@nddrylliog authored
Showing with 62 additions and 3 deletions.
  1. +1 −2  samples/Makefile
  2. +1 −1  samples/sample.use
  3. +60 −0 samples/sorting.ooc
View
3  samples/Makefile
@@ -2,5 +2,4 @@
all:
rm -rf snowflake
rock
- #(cd snowflake && make)
- colordiff snowflake snowflake-reference
+ (cd snowflake && make)
View
2  samples/sample.use
@@ -1 +1 @@
-Main: util.ooc
+Main: sorting.ooc
View
60 samples/sorting.ooc
@@ -0,0 +1,60 @@
+import math/Random
+
+List: class <X> {
+ data: X*
+ size: SizeT
+
+ init: func (=size) {
+ data = gc_malloc(X size * size)
+ }
+
+ get: func (index: Int) -> X {
+ data[index]
+ }
+
+ set: func (index: Int, element: X) {
+ data[index] = element
+ }
+
+ swap: func (i, j: Int) {
+ tmp := get(i)
+ (data[i], data[j]) = (get(j), tmp)
+ }
+
+ print: func (f: Func (X) -> String) {
+ "(" print()
+ for (i in 0..size) {
+ f(get(i)) print()
+ if (i < size - 1) ", " print()
+ }
+ ")" println()
+ }
+
+ bubbleSort!: func (compare: Func (X, X) -> Int) {
+ sorted := false
+ while (!sorted) {
+ sorted = true
+ for (i in 0..size - 1) {
+ if (compare(get(i), get(i + 1)) > 0) {
+ sorted = false
+ swap(i, i + 1)
+ }
+ }
+ }
+ }
+}
+
+test1: func {
+ l := List<Int> new(10)
+ for (i in 0..l size) {
+ l set(i, Random randInt(0, 200))
+ }
+ l print(|i| "%d" format(i))
+ l bubbleSort!(|a, b| a <=> b)
+ l print(|i| "%d" format(i))
+}
+
+main: func {
+ test1()
+}
+
Please sign in to comment.
Something went wrong with that request. Please try again.