Binary tree array scans

so i have to make a program that scans though an array returning it in the proper sequence of Left Node right, It doesn't have to be in a certain order, it just needs to print properly. i have some rough code that doesn't work and intuitively in my head and on paper i feel it should work but i cannot get it right. Can any one please assist me?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void LNRscan(int a[],int current)
        {
           
           if(a[current] != '\0')
           cout<<a[2*current+1]<<" ";
           
           cout<<a[current]<<" ";
           LNRscan(a,current+1);
           
           if(a[current] != '\0')
           cout<<a[2*current+2]<<" ";
           
           cout<<a[current]<<" ";
            
        }

i feel this is probably very easy and im just being very blind
Last edited on
here is the new function im working with but it is giving me a seg fault in the beggining
1
2
3
4
5
6
7
8
9
10
11
12
13
14
void LNRscan2(int a[], int size, int position)
{
int left_child = 2*position+1;
int right_child = 2*position+2;

if(a[position] != '\0')
LNRscan2(a,size,left_child);

cout<<position<<" ";

if(a[position] != '\0')
LNRscan2(a,size,right_child);

}

Last edited on
Topic archived. No new replies allowed.