File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -433,6 +433,7 @@ struct tree* findLargestBSTSubtree(struct tree *root) {
433433 return largestBST;
434434}
435435
436+ /* Find the nodes along the circumference of the tree . Select first and last nodes in each level followed by choosing the leaf nodes at each level */
436437
437438void findCircumference (struct tree *root)
438439{
@@ -449,6 +450,9 @@ void findCircumference(struct tree *root)
449450 {
450451 itr= s1.top ();
451452 s1.pop ();
453+
454+ // Concept of same two stack used for zig zag traversal
455+
452456 if (itr->left !=NULL )
453457 {
454458 s2.push (itr->left );
@@ -459,9 +463,10 @@ void findCircumference(struct tree *root)
459463 s2.push (itr->right );
460464 ++nextLevel;
461465 }
462- if ((itr->left == NULL && itr->right == NULL ) && (count != 0 ) && (count != currLevel))
463- printf (" \t %d" , itr->data );
464- if (count == 0 || count == currLevel-1 )
466+
467+ // Check for node at the circumference
468+
469+ if ((itr->left == NULL && itr->right == NULL ) || (count != 0 ) || (count != currLevel-1 ))
465470 printf (" \t %d" , itr->data );
466471 ++count;
467472 if (s1.empty ())
You can’t perform that action at this time.
0 commit comments