NUMBER_TOKEN NUMBER_TOKEN to NUMBER_TOKEN and vice versa that is what i did so again we're going to discuss the c plus plus and the java code so you can see the c plus plus code on the left and the java people can definitely follow their code that's on the right them they're mostly identical so you can definitely catch up so initially we are given the root of the tree and we declare our data structure that's result and the tree is empty we're going to return uh the data structure which will never have any uh zigzag traversal right after that i declare the queue and i initially push the route right and we have a flag which is initially marked as true so basically over here what i'm done is true means left to right and the opposite will mean uh right to left that is what i have been doing over here right after that i travis in the queue so you know always we take all the notes of that level so let's take all the notes of that level and what i do is i run a for loop okay i'm running a for loop on all the notes of that level and what i'm doing is i'm basically taking it popping it out so if your queue for an example has NUMBER_TOKEN NUMBER_TOKEN i will iterate on NUMBER_TOKEN and i'll iterate on NUMBER_TOKEN using this for loop got it right after that i check what i check is is left to right true if that's the case like this NUMBER_TOKEN that i'm taking out i'll put it in the front of my data structure and after that i'll put NUMBER_TOKEN if if the flag is true if it is not what i've done is i've smartly made sure that two will come at back then three will come right depending on this flag i'll either insert it uh from the front or i'll either insert it from the back simple enough right simple enough constructive and the rest thing remains the same i insert that into our vector or list and right after that i check left and right and i push it once i've done this entire iteration right i can i can always switch switch on the flags and i'll keep on the data structure whatever is on the row that's three two whatever is it i'll keep on the data structure once that is done i can definitely return my result so the thing that i did different from the previous level order traversal is this one flag and this while storing in a array or a vector whatever you can call it what i made sure is i made sure i either push it from the front or from the back that's that is the that is the logical thing that i did in order to get the zigzag order traversal so what will be the time complexity again the time complexity is going to be big off and similar to level order and what will be the space complexity that's going to be we go of n similar to the level order traversal so i hope you've understood the entire explanation as well as the code just in case you did please please please make sure you like this video because it took a lot of efforts to make this entire tree series also if you wish you can definitely drop in a comment that will keep motivating me to make such further series also if you're new to this channel please do consider subscribing
START_INTERACTION_TOKEN you've understood the entire explanation as well as the code just in case you did please please please make sure you like this video because it took a lot of efforts to make this entire tree series also if you wish you can definitely drop in a comment that will keep motivating me to make such further series also if you're new to this channel please do consider subscribing END_INTERACTION_TOKEN