ΜΆ
ISU
NIU
CS MS TBD

Basic operations for Linked Lists: appending a Node, checking cycles, deleting Nodes by value, prepending a Node, and inserting a Node.

• Difficulty: Easy
• Kind: Data Structures
• Platform: Basic Concepts
• Solved: N/A
• Time Complexity: O(N)
• Space Complexity: O(N)

### Insights

The main insight I think for working with Linked Lists involves traversal - iterating through the Linked List. It's often easier to work with arrays than Linked Lists directly.
// ES5 compliant.

else {
while (current.next != null) {
current = current.next;
}
}
};

else {
}
};

/** Remove by value not by index. */
let current = head, arr = []

while (current != null) {
if (current.val != val) arr.push(current.val)
current = current.next
}

return buildList(arr);
};

/** - Starting At 1 */
else {
for (var i = 1; i < position; i++) {
last = current;
current = current.next;
}
last.next = current;
}
};

if (head == null) return false;
else {
while (current != null) {
else return true;
current = current.next;
}
return false;
}
};

// Reinitialize each time
function init() {
}

function cycle() {
}

var testA = init();
var resultA = append(testA, 5);
declare_result(traverseList(testA) + " append 5", traverseList(expectationA), traverseList(resultA), array_equals(traverseList(expectationA), traverseList(resultA)));

var testB = init();
var resultB = checkCycle(testB)
declare_result(traverseList(testB) + " check is cycle", false, resultB, resultB === false);

var testC = cycle();
var resultC = checkCycle(testC)
declare_result(traverseList(testC) + " check is cycle", true, resultC, resultC === true);

var testD = init();
var resultD = prepend(testD, 5)
declare_result(traverseList(testD) + " prepend 5", traverseList(expectationD), traverseList(resultD), array_equals(traverseList(expectationD), traverseList(resultD)));

var testE = null;
var resultE = del(testE, 3);
declare_result("null delete 3", null, null, null === resultE);

var testF = init();
var resultF = del(testF, 3)
declare_result(traverseList(testF) + " delete 3", traverseList(expectationF), traverseList(resultF), array_equals(traverseList(expectationF), traverseList(resultF)));

var testG = init();