Just switching positions in the array:

来源: achicod 2009-08-08 02:54:56 [] [旧帖] [给我悄悄话] 本文已被阅读: 次 (443 bytes)
Pattern: A1 B1 A2 B2 ... An Bn
Position of the old: 0 1 2 3 4 5 ... 2n-1
New array stores old position: 0 2 4 ... 2n-2 1 3 5 ... 2n-1

Use two array:
OldArray store the initial pattern.
NewArray stores: Old[0] Old[2] Old[4] ... Old[(n-1)*2] Old[1] Old[3] Old[5] ... Old[2n-1]}.

For (i=0; i {
NewArray[i]=OldArray[i*2]
NewArray[n+i]=OldArray[i*2+1]
}

Memory = 2n*element size
O(n)=n
请您先登陆,再发跟帖!

发现Adblock插件

如要继续浏览
请支持本站 请务必在本站关闭Adblock

关闭Adblock后 请点击

请参考如何关闭Adblock

安装Adblock plus用户请点击浏览器图标
选择“Disable on www.wenxuecity.com”

安装Adblock用户请点击图标
选择“don't run on pages on this domain”