| |

VerySource

 Forgot password?
 Register
Search
View: 832|Reply: 3

Come and help

[Copy link]

3

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-2-17 13:30:01
| Show all posts |Read mode
The complete binary order of n nodes is stored in a one-dimensional array a, and an algorithm is designed to implement the traversal of the binary number
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-4-26 13:00:01
| Show all posts
It's complete, it's not easy

Suppose it is stored in 1,2, ... n

Starting from 1
Traverse i, recursively traverse 2i, recursively traverse 2i + 1
Reply

Use magic Report

0

Threads

10

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-5-24 09:00:01
| Show all posts
Reply

Use magic Report

0

Threads

10

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-5-24 09:15:01
| Show all posts
#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);
}
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list