#include <iostream>

using namespace std;

void push(int*,int*,int);

int main()
{
	int lenght = 0;
	int ahnentafel[100];
	for (int i=0;i<100;i++)
		ahnentafel[i] = 0;

	push(&ahnentafel[0],&lenght,2);
	push(&ahnentafel[0],&lenght,3);
	push(&ahnentafel[0],&lenght,4);
	push(&ahnentafel[0],&lenght,5);
	push(&ahnentafel[0],&lenght,6);
	push(&ahnentafel[0],&lenght,7);
	push(&ahnentafel[0],&lenght,8);

	//showw
	int pivot = 1;
	int cnt = 1;
	for (int i=0;i<lenght;i++)
	{
		cout << ahnentafel[i];
		cnt--;
		if (cnt==0)
		{
			cout << endl;
			pivot *= 2;
			cnt = pivot;
		}
	}

	system("pause");
	return 0;
}

int right(int i)
{
	return (i+1)*2;
}

int left(int i)
{
	return right(i)-1;
}

int parent(int i)
{
	return (i-1)/2;
}

void swap(int*ls, int *ln, int i, int j)
{
		int tmp = *(ls+i);
		*(ls+i) = *(ls+j);
		*(ls+j) = tmp;
}

void curse(int * ls,int * ln,int i)
{
	if (left(i)<(*ln) && *(ls+left(i))>*(ls+i))
	{
		swap(ls,ln,i,left(i));
		curse(ls,ln,left(i));
	}
	if (right(i)<(*ln) && *(ls+right(i))<=*(ls+i))
	{
		swap(ls,ln,i,right(i));
		curse(ls,ln,right(i));
	}
	if (i<(*ln))
		curse(ls,ln,i+1);
}

void push(int * ls,int * ln,int a)
{
	*(ls+(*ln)) = (*ls);
	(*ls) = a;
	(*ln)++;
	curse(ls,ln,0);
}