我正在尝试使用occam进行编程,我认为它并不容易理解,因为文档不太好。无论如何,我希望有人帮助我。
我正在努力学习如何制作一个简单的程序。在occam中进行冒泡排序。
#INCLUDE "course.module"
[32]INT x:
INT aux:
BOOL flag:
flag:= TRUE
aux:=0
--put values on the array
SEQ k=0 for 10
x[i] = -x[i]
-- bubble sort
WHILE (flag)
SEQ i = 0 for 9
IF
x[i] > x[i+1]
aux:= x[i]
x[i]:= x[i+1]
x[i+1] := aux
flag:= false
:
答案 0 :(得分:0)
代码中的一些提示可能对TiO-IDE may provide a place for online experimentation提供帮助和礼貌:
#INCLUDE "course.module"
PROC main( CHAN BYTE keyboard, screen, error )
[32]INT x:
INT aux:
BOOL flag:
SEQ -- ------------------------- BoSEQ:
SEQ i = 0 FOR 31 -- SEQ used as <-an-iterator->
x[i] := i -- put values on the array
SEQ i = 0 FOR 10 -- SEQ used as <-an-iterator->
x[i] := -x[i] -- put values on the array
flag := TRUE
WHILE ( flag ) -- WHILE
SEQ -- SEQ as a bubble sort
SEQ i = 0 FOR 10 -- SEQ used as <-an-iterator->
IF -- IF
x[i] > x[i+1] -- CASE: x[i] > x[i+1]
SEQ -- SEQ of steps
aux := x[i] -- 1
x[i] := x[i+1] -- 2
x[i+1] := aux -- 3
-- -- -- -- -- -- -- -- -- -- -- -- -- --
-- INTERESTING [occam-pi] FEATURE IS, THAT
-- [occam-pi] CAN _SWAP_ IN-PLACE
-- USING JUST x[i], x[i+1] := x[i+1], x[i]
TRUE -- OTHERWISE:
SKIP
-- SEQ used above as <-an-iterator-> got exhausted
flag := FALSE -- SET FALSE
-- ----------------------------- EoSEQ:
: -- main()