Printing BFS (Binary Tree) in Level Order with Specific Formatting

Just build one level at a time, e.g.: class Node(object): def __init__(self, value, left=None, right=None): self.value = value self.left = left self.right = right def traverse(rootnode): thislevel = [rootnode] while thislevel: nextlevel = list() for n in thislevel: print n.value, if n.left: nextlevel.append(n.left) if n.right: nextlevel.append(n.right) print thislevel = nextlevel t = Node(1, Node(2, Node(4, … Read more

How can I find the closest previous sibling with class using jQuery?

Try: $(‘li.current_sub’).prevAll(“li.par_cat:first”); Tested it with your markup: $(‘li.current_sub’).prevAll(“li.par_cat:first”).text(“woohoo”); <script src=”https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js”></script> <ul> <li class=”par_cat”></li> <li class=”sub_cat”></li> <li class=”sub_cat”></li> <li class=”par_cat”>// this is the single element I need to select</li> <li class=”sub_cat”></li> <li class=”sub_cat”></li> <li class=”sub_cat current_sub”>// this is where I need to start searching</li> <li class=”par_cat”></li> <li class=”sub_cat”></li> <li class=”par_cat”></li> </ul> will fill up the closest … Read more

jQuery find closest previous sibling with class

Try: $(‘li.current_sub’).prevAll(“li.par_cat:first”); Tested it with your markup: $(‘li.current_sub’).prevAll(“li.par_cat:first”).text(“woohoo”); <script src=”https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js”></script> <ul> <li class=”par_cat”></li> <li class=”sub_cat”></li> <li class=”sub_cat”></li> <li class=”par_cat”>// this is the single element I need to select</li> <li class=”sub_cat”></li> <li class=”sub_cat”></li> <li class=”sub_cat current_sub”>// this is where I need to start searching</li> <li class=”par_cat”></li> <li class=”sub_cat”></li> <li class=”par_cat”></li> </ul> will fill up the closest … Read more

tech