|
发表于 2020-5-24 09:00:01
|
显示全部楼层
#include<stdio.h>
//a[0] 没有用
void first(int a[],int n)
{
int cur,last;
cur=last=1;
// 找到最后一个元素的下标
while(last<n)
last=last*2+1;
last=last/2;
while(cur!=last)
{
printf("%d\t",a[cur]);
if(2*cur<n)
cur*=2;
else if(cur%2)
cur=cur/2+1;
else
cur++;
}
printf("%d\t",a[last]);
}
void main()
{
int a[]={0,1,2,3,4,5,6,7,8,9};
int n=sizeof(a)/sizeof(a[0]);
first(a,n);
} |
|