永发信息网

第一个循环for j=k step-1 until 1 do,为什么j要从k到1,而不是1到k?

答案:2  悬赏:70  手机版
解决时间 2021-02-15 19:07
  • 提问者网友:未信
  • 2021-02-14 19:09
算法如下:Input: A sequence A1,A2,….An where each Ai is a k-tuple
(ai1,ai2,…,aik )
with aij an integer in the range 0 to m-1. (A convenient data structure for this sequence of k-tuples is an n*k array)
Output: A sequence B1,B2,….Bn which is a permutation of A1,A2,….An such that B<=B for 1<=iMethod. In transferring a k-tuple A to some bucket,only a pointer to A is actually moved. Thus A can be added to a bucket in fixed time rather than time bounded by k. We use a queue called QUEUE to hold the" current" sequence of elements. An array Qof m buckets is also used,where bucket Q[i] is intended to hold those k-tuples that have the integer i in the component currently under consideration, The algorithm is show as :
begin
place A,A,......,A in QUEUE;
for j=k step-1 until 1 do
begin
for l=0 until m-1 do make Q[l] empty;
while QUEUE not empty do
begin
let A be the first element in QUEUE;
move A from QUEUE to bucket Q[a]
end;
for l=0 until m-1 do
concatenate contents of Q[l] to the end of QUEUE
end
end

为什么要move A from QUEUE to bucket Q[a](这里似乎遗漏了一些下标)?bucket Q[a]的数据结构应该是怎样的?
为什么要for l=0 until m-1 do concatenate contents of Q[l] to the end of QUEUE?
最佳答案
  • 五星知识达人网友:鱼芗
  • 2021-02-14 19:27
i Method. In transferring a k-tuple A
全部回答
  • 1楼网友:野慌
  • 2021-02-14 20:09
搜一下:第一个循环for j=k step-1 until 1 do,为什么j要从k到1,而不是1到k?
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯