Learn basic concept of c , c++ and python programming in regularcodes.com

Spread the post

Print all cousins of node that is given as input

Given a binary tree node. finding the all cousins of given node in this binary tree. .

For example Given binary tree are contain following nodes.

12475836910

Output

View cousin of nodes 10.

12475836910

Node 10 are cousins [ 8 ,7] represent are blue circle.

Another example.

12475836910

Node 5 are cousin are 6.

View pointers and nodes of tree.

Stack Areamainhead(pointer) NULLroot(pointer)tail(pointer) NULL Heap Areastruct Treedata (int)= 1left (pointer) right (pointer) struct Treedata (int)= 2left (pointer) right (pointer) struct Treedata (int)= 3left (pointer)= NULLright (pointer) struct Treedata (int)= 4left (pointer) right (pointer)= NULLstruct Treedata (int)= 5left (pointer)= NULLright (pointer) struct Treedata (int)= 6left (pointer) right (pointer) struct Treedata (int)= 7left (pointer)= NULLright (pointer)= NULLstruct Treedata (int)= 8left (pointer)= NULLright (pointer)= NULLstruct Treedata (int)= 9left (pointer)= NULLright (pointer)= NULLstruct Treedata (int)= 10left (pointer)= NULLright (pointer)= NULL

Try it Yourself

C program for Print All cousins of given node in binary tree.


Output

view process

Stack Areamainhead(pointer)root(pointer)tail(pointer)find_cousinauxiliary(pointer)level (int) =2node (int) =5status (int) =1temp(pointer) Heap Areastruct Treedata (int)= 1left (pointer) right (pointer) struct Treedata (int)= 2left (pointer) right (pointer) struct Treedata (int)= 3left (pointer)= NULLright (pointer) struct Treedata (int)= 4left (pointer) right (pointer)= NULLstruct Treedata (int)= 5left (pointer)= NULLright (pointer) struct Treedata (int)= 6left (pointer) right (pointer) struct Treedata (int)= 7left (pointer)= NULLright (pointer)= NULLstruct Treedata (int)= 8left (pointer)= NULLright (pointer)= NULLstruct Treedata (int)= 9left (pointer)= NULLright (pointer)= NULLstruct Treedata (int)= 10left (pointer)= NULLright (pointer)= NULLstruct Queuelevel (int)= 0parent (pointer)= NULLlink (pointer) next (pointer) struct Queuelevel (int)= 1parent (pointer) link (pointer) next (pointer) struct Queuelevel (int)= 1parent (pointer) link (pointer) next (pointer) struct Queuelevel (int)= 2parent (pointer) link (pointer) next (pointer) struct Queuelevel (int)= 2parent (pointer) link (pointer) next (pointer) struct Queuelevel (int)= 2parent (pointer) link (pointer) next (pointer) struct Queuelevel (int)= 3parent (pointer) link (pointer) next (pointer) struct Queuelevel (int)= 3parent (pointer) link (pointer) next (pointer) struct Queuelevel (int)= 3parent (pointer) link (pointer) next (pointer) struct Queuelevel (int)= 3parent (pointer) link (pointer) next (pointer)= NULL

Try it Yourself

Spread the post

Recommended Posts: