Easy folow the procedure, code is doing -
Copying value of the node to q -> data.
saving the left node pointer to the ptr.
step 1 tree will be like
2
1 3
(null) 1 ( not given)
step 2
2
1 3
(null) 1 ( not given) (null) 3 ( not given) { 3 is the left child of 3 of earlier node}
step 3
2
2 ( not given) 3
1 (null) 3 ( not given) { 3 is the left child of 3 of earlier node}
(null) 1 ( not given)