Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-rosetta/blob/main/drafts/rosettacode/bubble-sort.wiki # omega-rosetta aien-dev/omega-rosetta Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-rosetta / drafts / rosettacode / bubble-sort.wiki` 91 lines ยท 1535 bytes Raw Blame History 1 =={{header|Omegese}}== 2 {{works with|omc|sha256 `2c824805`, aien-dev/omega-mv `e5b32567`, Linux AArch64}} 3 Omega has no imports, so the small output helpers (emit and friends) are part of the program. 4 5 om2 6 text nl "\n" 7 text sp " " 8 text minus "-" 9 note emit writes every byte of a to stdout; a short write is retried, an error exits 1 10 fn emit a view uchar * to void 11 o = ulong 0 12 while lt o len a bound 4096 13 k = write 1 a o sub len a o 14 if le k 0 15 exit 1 16 end 17 o = add o ulong k 18 end 19 end 20 note emitu writes n in decimal; 20 digits hold every ulong 21 fn emitu n ulong to void 22 d = new uchar 20 0 23 i = ulong 20 24 v = n 25 while true bound 20 26 i = sub i 1 27 put d i uchar add rem v 10 48 28 v = div v 10 29 if eq v 0 30 break 31 end 32 end 33 emit part d i sub 20 i 34 end 35 note emiti writes a signed n; the magnitude is taken as a ulong so the minimum long cannot overflow 36 fn emiti n long to void 37 if lt n 0 38 emit minus 39 emitu add bitcast ulong not n 1 40 else 41 emitu ulong n 42 end 43 end 44 fn bsort a edit long 10 to void 45 for p ulong 9 46 swapped = false 47 for i ulong 9 48 if gt get a i get a add i 1 49 t = get a i 50 put a i get a add i 1 51 put a add i 1 t 52 swapped = true 53 end 54 end 55 if not swapped 56 break 57 end 58 end 59 end 60 fn show a view long 10 to void 61 for i ulong 10 62 if gt i 0 63 emit sp 64 end 65 emiti get a i 66 end 67 emit nl 68 end 69 fn main to int 70 a = new long 10 0 71 put a 0 5 72 put a 1 -3 73 put a 2 9 74 put a 3 0 75 put a 4 12 76 put a 5 -8 77 put a 6 7 78 put a 7 7 79 put a 8 1 80 put a 9 100 81 show a 82 bsort a 83 show a 84 ret 0 85 end 86 87 {{out}} 88

89 5 -3 9 0 12 -8 7 7 1 100

90 -8 -3 0 1 5 7 7 9 12 100

91