如何在O(n)上不停地转播
<><>>>>> http://strong>not homework, only to Save theenergy of some key板 strokes to written comments about homework!
如何在O(n)上不停地转播
<><>>>>> http://strong>not homework, only to Save theenergy of some key板 strokes to written comments about homework!
Let s say that we have the following threaded tree representation in C:
typedef struct threaded_binary_tree {
int value;
// Flag that tells whether right points to a right child or to a next
// node in inorder.
bool right_is_child;
struct threaded_binary_tree *left, *right;
} threaded_binary_tree;
然后,在<条码>O(1)条码>上检索。
void inorder(threaded_binary_tree *node)
{
threaded_binary_tree *prev = NULL;
// Ignore empty trees
if (node == NULL)
return;
// First, go to the leftmost leaf of the tree
while (node->left != NULL)
node = node->left;
while (node != NULL) {
// Nodes are visited along going upward in the tree
printf("%d
", node->value);
prev = node;
node = node->right;
if (prev->right_is_child) {
// We re descending into tree
if (node != NULL) {
// Again, go to the leftmost leaf in this subtree
while (node->left != NULL)
node = node->left;
}
}
// else, we re climbing up in the tree
}
}
警告:我没有这样做。
这是在 Java撰写的法典:
public void inOrder() {
Node<T> curr = root;
boolean visited = false; //I haven t come across the node from which I came
while (curr != null) {
if (!visited && curr.left != null) { //Go to leftmost node
curr = curr.left;
} else {
System.out.println(curr.head + " ");
if (curr.right != null) { //I prioritize having childs than "threaded sons"
curr = curr.right;
visited = false;
} else {
curr = curr.rightThreaded;
visited = true; //Means that I will come back to a node I ve already looped, but now i ll print it, except if i m at the last node
}
}
}
}
纽埃语是一种内装饰语 树木:
private static class Node<T> {
private T head;
private Node<T> left;
private Node<T> right;
private Node<T> leftThreaded;
private Node<T> rightThreaded;
public Node(T head, Node<T> leftThreaded, Node<T> rightThreaded) {
this.head = head;
this.leftThreaded = leftThreaded;
this.rightThreaded = rightThreaded;
}
}
How to implement a double linked list with only one pointer? It takes O(1) time to find the prev and next Node. struct Node { int val; Node* p; };
Currently we are filtering and sorting data with a datatable. /// <summary> /// Filters the data table and returns a new data table with only the filtered rows. /// </summary>...
How can I efficiently implement a list data structure where I can have 2 views to the head and end of the list, that always point to a head a tail of a list without expensive calls to reverse. i.e: ...
I need to store a 2d matrix containing zip codes and the distance in km between each one of them. My client has an application that calculates the distances which are then stored in an Excel file. ...
According to various sources, such as Wikipedia and various .edu websites found by Google, the most common ways for a hash table to resolve collisions are linear or quadratic probing and chaining. ...
I have an ASP.NET web application and I want to be able to take items from a master list and store them temporarliy into one of four other lists. The other lists need to survive post backs so that ...
I am a new student in the compilers world ^_^ and I want to know is legal represent negative number in the stack. For example: infix: 1-5=-4 postfix: 15- The statements are: push(1) push(5) x=...
I am trying to figure out what type of structure or container I should use for a quick project. I need to have an unknown number of sets that will be entered from the GUI (each one will have a name, ...