Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
</body>
</html>
 
var insert = function(value, parent) {
  var node = { val: value };
  if (parent) {
    // Connect a node to the parent.
    parent.next = node;
  }
  
  return node;
}
var remove = function(head, position) {
  if (head == null) {
    return null;
  }
  else if (position === 0) {
    return head.next;
  }
  else {
    var n = head;
    for (var i = 0; i < position - 1; i++) {
      n = n.next;
    }
    
    n.next = n.next.next;
    return head;
 }
}
var traverse = function(root, callback) {
  while (root) {
    if (callback) {
      callback(root);
    }
    
    root = root.next;
  }
}
var root = insert(1);
var child = insert(2, root);
child = insert(3, child);
child = insert(4, child);
child = insert(5, child);
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
primaryobjectspro
0viewers