Print path from a node to root of given Complete Binary Tree | C ++ program for the above approach ; Function to print the path from node to root ; Iterate until root is reached ; Print the value of the current node ; Move to parent of the current node ; Driver Code
#include <iostream> NEW_LINE using namespace std ; void path_to_root ( int node ) { while ( node >= 1 ) { cout << node << ' ▁ ' ; node /= 2 ; } } int main ( ) { int N = 7 ; path_to_root ( N ) ; return 0 ; }