Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Standard tree traversal loop (yes, missing some obvious conditionals I didn't feel like typing out):

    var todo = new List<T>();
    todo.append(root);
    while (var item = todo.pop_front()) {
      todo.append(item.left); // or .prepend for depth-first
      todo.append(item.right); // or .prepend()
      // do stuff...
    }


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: