3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Node { public $data = null; public $parent = null; public $left = null; public $right = null; } function mirror_recursive($root) { if ($root === null) { return; } mirror_recursive($root->left); mirror_recursive($root->right); $temp = $root->left; $root->left = $root->right; $root->right = $temp; } function mirror_norec($root) { $queue = array(); array_unshift($queue, $root); while (!empty($queue)) { $cnode = array_pop($queue); if ($cnode->left !== null) array_unshift($queue, $cnode->left); if ($cnode->right !== null) array_unshift($queue, $cnode->right); $temp = $cnode->left; $cnode->left = $cnode->right; $cnode->right = $temp; } } function inorder_traverse($root) { if ($root->left !== null) inorder_traverse($root->left); echo $root->data . " "; if ($root->right !== null) inorder_traverse($root->right); } $root = new Node(); $n1 = new Node(); $n2 = new Node(); $n11 = new Node(); $n12 = new Node(); $n13 = new Node(); $n14 = new Node(); $n15 = new Node(); $n21 = new Node(); $root->data = 0; $n1->data = 1; $n2->data = 2; $n11->data = 11; $n12->data = 12; $n13->data = 13; $n14->data = 14; $n15->data = 15; $n21->data = 21; $root->left = $n1; $root->right = $n2; $n1->left = $n11; $n1->right = $n12; $n11->left = $n13; $n12->right = $n14; $n13->left = $n15; $n2->right = $n21; inorder_traverse($root); echo "<br>"; mirror_recursive($root); inorder_traverse($root); echo "<br>"; mirror_norec($root); inorder_traverse($root); ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OpNUP
function name:  (null)
number of ops:  79
compiled vars:  !0 = $root, !1 = $n1, !2 = $n2, !3 = $n11, !4 = $n12, !5 = $n13, !6 = $n14, !7 = $n15, !8 = $n21
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     0  E >   NEW                                              $9      'Node'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $9
   47     3        NEW                                              $12     'Node'
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !1, $12
   48     6        NEW                                              $15     'Node'
          7        DO_FCALL                                      0          
          8        ASSIGN                                                   !2, $15
   49     9        NEW                                              $18     'Node'
         10        DO_FCALL                                      0          
         11        ASSIGN                                                   !3, $18
   50    12        NEW                                              $21     'Node'
         13        DO_FCALL                                      0          
         14        ASSIGN                                                   !4, $21
   51    15        NEW                                              $24     'Node'
         16        DO_FCALL                                      0          
         17        ASSIGN                                                   !5, $24
   52    18        NEW                                              $27     'Node'
         19        DO_FCALL                                      0          
         20        ASSIGN                                                   !6, $27
   53    21        NEW                                              $30     'Node'
         22        DO_FCALL                                      0          
         23        ASSIGN                                                   !7, $30
   54    24        NEW                                              $33     'Node'
         25        DO_FCALL                                      0          
         26        ASSIGN                                                   !8, $33
   56    27        ASSIGN_OBJ                                               !0, 'data'
         28        OP_DATA                                                  0
   57    29        ASSIGN_OBJ                                               !1, 'data'
         30        OP_DATA                                                  1
   58    31        ASSIGN_OBJ                                               !2, 'data'
         32        OP_DATA                                                  2
   59    33        ASSIGN_OBJ                                               !3, 'data'
         34        OP_DATA                                                  11
   60    35        ASSIGN_OBJ                                               !4, 'data'
         36        OP_DATA                                                  12
   61    37        ASSIGN_OBJ                                               !5, 'data'
         38        OP_DATA                                                  13
   62    39        ASSIGN_OBJ                                               !6, 'data'
         40        OP_DATA                                                  14
   63    41        ASSIGN_OBJ                                               !7, 'data'
         42        OP_DATA                                                  15
   64    43        ASSIGN_OBJ                                               !8, 'data'
         44        OP_DATA                                                  21
   66    45        ASSIGN_OBJ                                               !0, 'left'
         46        OP_DATA                                                  !1
   67    47        ASSIGN_OBJ                                               !0, 'right'
         48        OP_DATA                                                  !2
   68    49        ASSIGN_OBJ                                               !1, 'left'
         50        OP_DATA                                                  !3
   69    51        ASSIGN_OBJ                                               !1, 'right'
         52        OP_DATA                                                  !4
   70    53        ASSIGN_OBJ                                               !3, 'left'
         54        OP_DATA                                                  !5
   71    55        ASSIGN_OBJ                                               !4, 'right'
         56        OP_DATA                                                  !6
   72    57        ASSIGN_OBJ                                               !5, 'left'
         58        OP_DATA                                                  !7
   73    59        ASSIGN_OBJ                                               !2, 'right'
         60        OP_DATA                                                  !8
   75    61        INIT_FCALL                                               'inorder_traverse'
         62        SEND_VAR                                                 !0
         63        DO_FCALL                                      0          
   76    64        ECHO                                                     '%3Cbr%3E'
   77    65        INIT_FCALL                                               'mirror_recursive'
         66        SEND_VAR                                                 !0
         67        DO_FCALL                                      0          
   78    68        INIT_FCALL                                               'inorder_traverse'
         69        SEND_VAR                                                 !0
         70        DO_FCALL                                      0          
   79    71        ECHO                                                     '%3Cbr%3E'
   80    72        INIT_FCALL                                               'mirror_norec'
         73        SEND_VAR                                                 !0
         74        DO_FCALL                                      0          
   81    75        INIT_FCALL                                               'inorder_traverse'
         76        SEND_VAR                                                 !0
         77        DO_FCALL                                      0          
   82    78      > RETURN                                                   1

Function mirror_recursive:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 4
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OpNUP
function name:  mirror_recursive
number of ops:  22
compiled vars:  !0 = $root, !1 = $temp
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
   13     1        TYPE_CHECK                                    2          !0
          2      > JMPZ                                                     ~2, ->4
   14     3    > > RETURN                                                   null
   17     4    >   INIT_FCALL_BY_NAME                                       'mirror_recursive'
          5        CHECK_FUNC_ARG                                           
          6        FETCH_OBJ_FUNC_ARG                               $3      !0, 'left'
          7        SEND_FUNC_ARG                                            $3
          8        DO_FCALL                                      0          
   18     9        INIT_FCALL_BY_NAME                                       'mirror_recursive'
         10        CHECK_FUNC_ARG                                           
         11        FETCH_OBJ_FUNC_ARG                               $5      !0, 'right'
         12        SEND_FUNC_ARG                                            $5
         13        DO_FCALL                                      0          
   19    14        FETCH_OBJ_R                                      ~7      !0, 'left'
         15        ASSIGN                                                   !1, ~7
   20    16        FETCH_OBJ_R                                      ~10     !0, 'right'
         17        ASSIGN_OBJ                                               !0, 'left'
         18        OP_DATA                                                  ~10
   21    19        ASSIGN_OBJ                                               !0, 'right'
         20        OP_DATA                                                  !1
   22    21      > RETURN                                                   null

End of function mirror_recursive

Function mirror_norec:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
2 jumps found. (Code = 44) Position 1 = 37, Position 2 = 7
Branch analysis from position: 37
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 19
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 27
Branch analysis from position: 22
2 jumps found. (Code = 44) Position 1 = 37, Position 2 = 7
Branch analysis from position: 37
Branch analysis from position: 7
Branch analysis from position: 27
Branch analysis from position: 19
filename:       /in/OpNUP
function name:  mirror_norec
number of ops:  38
compiled vars:  !0 = $root, !1 = $queue, !2 = $cnode, !3 = $temp
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   RECV                                             !0      
   26     1        ASSIGN                                                   !1, <array>
   27     2        INIT_FCALL                                               'array_unshift'
          3        SEND_REF                                                 !1
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                                 
   29     6      > JMP                                                      ->34
   30     7    >   INIT_FCALL                                               'array_pop'
          8        SEND_REF                                                 !1
          9        DO_ICALL                                         $6      
         10        ASSIGN                                                   !2, $6
   31    11        FETCH_OBJ_R                                      ~8      !2, 'left'
         12        TYPE_CHECK                                  1020          ~8
         13      > JMPZ                                                     ~9, ->19
         14    >   INIT_FCALL                                               'array_unshift'
         15        SEND_REF                                                 !1
         16        FETCH_OBJ_R                                      ~10     !2, 'left'
         17        SEND_VAL                                                 ~10
         18        DO_ICALL                                                 
   32    19    >   FETCH_OBJ_R                                      ~12     !2, 'right'
         20        TYPE_CHECK                                  1020          ~12
         21      > JMPZ                                                     ~13, ->27
         22    >   INIT_FCALL                                               'array_unshift'
         23        SEND_REF                                                 !1
         24        FETCH_OBJ_R                                      ~14     !2, 'right'
         25        SEND_VAL                                                 ~14
         26        DO_ICALL                                                 
   33    27    >   FETCH_OBJ_R                                      ~16     !2, 'left'
         28        ASSIGN                                                   !3, ~16
   34    29        FETCH_OBJ_R                                      ~19     !2, 'right'
         30        ASSIGN_OBJ                                               !2, 'left'
         31        OP_DATA                                                  ~19
   35    32        ASSIGN_OBJ                                               !2, 'right'
         33        OP_DATA                                                  !3
   29    34    >   ISSET_ISEMPTY_CV                                 ~21     !1
         35        BOOL_NOT                                         ~22     ~21
         36      > JMPNZ                                                    ~22, ->7
   37    37    > > RETURN                                                   null

End of function mirror_norec

Function inorder_traverse:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 9
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 20
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
Branch analysis from position: 9
filename:       /in/OpNUP
function name:  inorder_traverse
number of ops:  21
compiled vars:  !0 = $root
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     0  E >   RECV                                             !0      
   41     1        FETCH_OBJ_R                                      ~1      !0, 'left'
          2        TYPE_CHECK                                  1020          ~1
          3      > JMPZ                                                     ~2, ->9
          4    >   INIT_FCALL_BY_NAME                                       'inorder_traverse'
          5        CHECK_FUNC_ARG                                           
          6        FETCH_OBJ_FUNC_ARG                               $3      !0, 'left'
          7        SEND_FUNC_ARG                                            $3
          8        DO_FCALL                                      0          
   42     9    >   FETCH_OBJ_R                                      ~5      !0, 'data'
         10        CONCAT                                           ~6      ~5, '+'
         11        ECHO                                                     ~6
   43    12        FETCH_OBJ_R                                      ~7      !0, 'right'
         13        TYPE_CHECK                                  1020          ~7
         14      > JMPZ                                                     ~8, ->20
         15    >   INIT_FCALL_BY_NAME                                       'inorder_traverse'
         16        CHECK_FUNC_ARG                                           
         17        FETCH_OBJ_FUNC_ARG                               $9      !0, 'right'
         18        SEND_FUNC_ARG                                            $9
         19        DO_FCALL                                      0          
   44    20    > > RETURN                                                   null

End of function inorder_traverse

Class Node: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
169.47 ms | 1415 KiB | 22 Q