|
#include <stdio.h>
// a [0] is useless
void first (int a [], int n)
{
int cur, last;
cur = last = 1;
// Find the index of the last element
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);
} |
|