c语言构造数组二叉树

#include "stdafx.h"
#include
#include

const int nodecnt = 32768;
int tree[nodecnt];//下标从1开始

int _tmain(int argc, _TCHAR* argv[])
{
	int count = 9;
	int num[10] = { 6, 3, 8, 5, 2, 9, 4, 7, 10 };;
	
	int x = 1;
	int end = 1;

	int i = 1;
	
	
	
	tree[1] = num[0];
	
	for (i = 1; i tree[x])
				x = 2 * x + 1;
			else if (num[i] < tree[x]){
				x = 2 * x;
			}

		}

		tree[x] = num[i];
		if (end < x)
			end = x;//记录tree数组中最后一个元素的下标
	}
	for (i = 1; i <= end;i++)
		{
			printf("%d  ", tree[i]);
		}
	return 0;
}

你可能感兴趣的:(基础算法)