Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
36
Task/Permutations/PowerBASIC/permutations.basic
Normal file
36
Task/Permutations/PowerBASIC/permutations.basic
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
#COMPILE EXE
|
||||
#DIM ALL
|
||||
GLOBAL a, i, j, k, n AS INTEGER
|
||||
GLOBAL d, ns, s AS STRING 'dynamic string
|
||||
FUNCTION PBMAIN () AS LONG
|
||||
ns = INPUTBOX$(" n =",, "3") 'input n
|
||||
n = VAL(ns)
|
||||
DIM a(1 TO n) AS INTEGER
|
||||
FOR i = 1 TO n: a(i)= i: NEXT
|
||||
DO
|
||||
s = " "
|
||||
FOR i = 1 TO n
|
||||
d = STR$(a(i))
|
||||
s = BUILD$(s, d) ' s & d concatenate
|
||||
NEXT
|
||||
? s 'print and pause
|
||||
i = n
|
||||
DO
|
||||
DECR i
|
||||
LOOP UNTIL i = 0 OR a(i) < a(i+1)
|
||||
j = i+1
|
||||
k = n
|
||||
DO WHILE j < k
|
||||
SWAP a(j), a(k)
|
||||
INCR j
|
||||
DECR k
|
||||
LOOP
|
||||
IF i > 0 THEN
|
||||
j = i+1
|
||||
DO WHILE a(j) < a(i)
|
||||
INCR j
|
||||
LOOP
|
||||
SWAP a(i), a(j)
|
||||
END IF
|
||||
LOOP UNTIL i = 0
|
||||
END FUNCTION
|
||||
Loading…
Add table
Add a link
Reference in a new issue