 |
VFP 愛用者社區 本討論區為 Visual Foxpro 愛用者經驗交流的地方, 請多多利用"搜尋"的功能, 先查看看有無前例可循, 如果還有不懂的再發問. 部份主題有附加檔案, 須先註冊成為社區居民才可以下載.
|
上一篇主題 :: 下一篇主題 |
發表人 |
內容 |
sych
註冊時間: 2004-12-28 文章: 11
第 1 樓
|
發表於: 星期四 十二月 14, 2006 3:15 pm 文章主題: 求n个数的全排列 |
|
|
set talk off
clea
local m,n,i,j,p,s
n=4
dime p(n)
m=1
?
for s=1 to n
m=m*s
p(s)=s
??p(s)
endfor
for s=2 to m
i=n
do whil not p(i-1)<p(i)
i=i-1
enddo
j=n
do whil not p(i-1)<p(j)
j=j-1
enddo
p(i-1)=p(i-1)+p(j)
p(j)=p(i-1)-p(j)
p(i-1)=p(i-1)-p(j)
for j=0 to (n-i-1)/2
p(i+j)=p(i+j)+p(n-j)
p(n-j)=p(i+j)-p(n-j)
p(i+j)=p(i+j)-p(n-j)
endfor
?
for j=1 to n
??p(j)
endfor
endfor
retu |
|
回頂端 |
|
 |
|
|
您 無法 在這個版面發表文章 您 無法 在這個版面回覆文章 您 無法 在這個版面編輯文章 您 無法 在這個版面刪除文章 您 無法 在這個版面進行投票 您 無法 在這個版面附加檔案 您 無法 在這個版面下載檔案
|
|