Nerevarine
Incarnate
Index n = root
Index 2n+1 = left child
Index 2n+2 = right child
If im not mistaken.
Index 2n+1 = left child
Index 2n+2 = right child
If im not mistaken.
so both child will be greater than parent? as far as i reme,i remember reading somewhere that in an array representation of a tree,
if node: i
Child: 2*i, 2*i+1
Parent: i/2
Is this a correct way to represent the array elements as nodes of a binary tree?
any explanation why i dont get why child is 2*ii remember reading somewhere that in an array representation of a tree,
if node: i
Child: 2*i, 2*i+1
Parent: i/2
Is this a correct way to represent the array elements as nodes of a binary tree?
Exactly!When you create ar[5], here the 5 refers to size of array.
But programming index starts from 0, not one.
So ar[0], 1,2,3,4 are your entries
When you create ar[5], here the 5 refers to size of array.
But programming index starts from 0, not one.
So ar[0], 1,2,3,4 are your entries
My C++ knowledge is quite dusty but from whatever I remember if you assign an array value to wrong index it won't enter & here a 'for' loop is used which I presume starts from i=1 with +1 increment till i=5 which will result in only 4 entries as array[5] entry will be ignored.But he should still get 5 entries right 0,1,2,3,4
Sent from my iPhone using Tapatalk
My C++ knowledge is quite dusty but from whatever I remember if you assign an array value to wrong index it won't enter & here a 'for' loop is used which I presume starts from i=1 with +1 increment till i=5 which will result in only 4 entries as array[5] entry will be ignored.
You mean i<=5Yeah if you start for loop with i=1 till i<5 then you will get 4 values only.
Sent from my iPhone using Tapatalk
You mean i<=5
For i=5 the loop will try to assign array[5] which will fail as valid values to assign are array[0,1,2,3,4]. The correct loop should be i=0;i<5;i++But i=1 to i<=5 will give 5 inputs wont it?
Sent from my iPhone using Tapatalk
So anyone still uses the good old blue coloured turbo c++