Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
613 B
16
Indexable
Never
     1
  2    3
4   5

4 5 2 3 1

Find the bugs :

void reverseLevelOrder(Node node)  
{ 
    Stack<Node> S = new Stack(); 
    Queue<Node> Q = new LinkedList(); 
    Q.add(node); 

    while (Q.isEmpty() == false)  
    { 
        node = Q.peek(); 
        Q.remove(); 
        S.push(node); 

        if (node.left != null) 
        {
            Q.add(node.left); 
        }
   
        if (node.right != null) 
        {
            Q.add(node.right);  
        }
                
    } 
   
    while (S.empty() == true)  
    { 
        node = S.peek(); 
        System.out.print(node.data + " "); 
    } 
}
Leave a Comment