The Doc Dialer, Part 2: A Browser Independent Version: Updating the Display
The Doc Dialer, Part 2: A Browser Independent Version
Updating the Display
At any one point in the trie data structure we need to print to the phone display all matching names so far. Even after a single step down the hierarchy, all names stored in that particular branch should be reported. It means that for each object we visit during the descend, we need to print all records that are linked to element at index 1. We change slightly the updateBoard()
function from our previous column:
function updateBoard(trieNode) {
if (trieNode[1]) {
addEmployeeToDisplay(trieNode[1]);
}
for (var i=2; i
First, we check if the head of the link list exists. If it does, we add all employees stored in the link list:
if (trieNode[1]) {
addEmployeeToDisplay(trieNode[1]);
}
The function addEmployeeToDisplay()
just goes over the link list and checks out the proper entries in the printList
array:
function addEmployeeToDisplay(leafNode) {
while (leafNode) {
printList[leafNode.empIndex] = true;
leafNode = leafNode.next;
}
}
Once we are done checking out the names, we continue to descend along the trie data structure, trying all eight possible pointers for the keys 2 through 9. For each found pointer, we call the updateBoard()
function recursively, to collect all names that appear under currentTrie
.
Next: How to handle events
Produced by Yehuda Shiran and Tomer Shiran
Created: February 28, 2000
Revised: April 26, 2000
URL: https://www.webreference.com/js/column58/8.html