<commit_before>/* 4.4 Given a binary search tree, design an algorithm which creates a linked
 * list of all the nodes at each depth (i.e., if you have a tree with depth D,
 * you will have D linked lists).
 * */

import java.util.ArrayList;
import java.util.Queue;
import java.util.LinkedList;
import java.util.List;
import java.util.Iterator;

public class P0404 {
   private class Node {
      int value;
      Node left, right;

      public Node(int value) {
         this.value = value;
      }
   }

   public void levelOrder(Node root, int level, int count, 
      List<Node> list) {

      if (root == null) return;

      if (count == level) {
         list.add(root);
         return;
      }

      if (count < level) {
         levelOrder(root.left, level, count + 1, list);
         levelOrder(root.right, level, count + 1, list);
      }
   }

   public void levelOrder(Node root, int level, ArrayList<List<Node>> list) {<commit_msg>add some comments<commit_after>/* 4.4 Given a binary search tree, design an algorithm which creates a linked
 * list of all the nodes at each depth (i.e., if you have a tree with depth D,
 * you will have D linked lists).
 * */

import java.util.ArrayList;
import java.util.Queue;
import java.util.LinkedList;
import java.util.List;
import java.util.Iterator;

public class P0404 {
   private class Node {
      int value;
      Node left, right;

      public Node(int value) {
         this.value = value;
      }
   }

   public void levelOrder(Node root, int level, int count, 
      List<Node> list) {

      if (root == null) return;

      if (count == level) {
         list.add(root);
         return;
      }

      if (count < level) {
         levelOrder(root.left, level, count + 1, list);
         levelOrder(root.right, level, count + 1, list);
      }
   }

    // time complexity: O(N)
    // space complexity: O(lgN), worst O(N)
   public void levelOrder(Node root, int level, ArrayList<List<Node>> list) {
{'fraction_non_alphanumeric': 0.11009639776763064, 'fraction_numerical': 0.008117706747843734, 'mean_word_length': 2.417677642980936, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3107126', 'n_tokens_mistral': 617, 'n_tokens_neox': 592, 'n_words': 216}