我正在尝试使用红黑树实现字典.
我测试了插入方法,它似乎工作得很好,RBtree似乎保持正确的形状和颜色.执行二叉树节点删除的方法似乎是正确的,但是我在删除结束时调用的deleteFixUp方法遇到了很大的问题.
你想帮我搞清楚我做错了什么吗?当然,如果您有任何改进我的代码的建议,我们将非常感激.
RBTreeWParentDictionary.java(这里我实现了RedBlackTree)
package dictionary;
import java.util.Comparator;
public class RBTreeWParentDictionary<K, V> implements IDictionary<K, V> {
/**
* The root node of the RBTreeWParentDictionary
*/
public RBTreeWParentNode<K, V> root;
/**
* Object used to compare two T objects.
*/
private Comparator<K> comparator;
private int length;
/**
* Creates the dictionary based on red/black tree with null root
*
* @param comparator
* The comparator for keys
*/
public RBTreeWParentDictionary(Comparator<K> comparator) {
this.root = null;
this.comparator = comparator;
this.length = 0; …Run Code Online (Sandbox Code Playgroud) 我正在使用Twitter Bootstrap开展一个项目.它由一个单独的html页面组成,并且在jQuery的帮助下,我从服务器获取数据和页面.
我对整个项目有一个独特的模态,每当我展示它时,我都会在身体中附加数据.我的问题是,当我关闭模态并用新内容重新打开它时,javascript停止工作并且没有打开模态.如果我在关闭和打开之间添加一些延迟,它可以在某些浏览器上运行但在其他浏览器上没有(例如chrome)并且代码非常难看.
我认为我应该在打开一个新模式之前关闭模态时绑定一个事件.这是我打开模态的代码:
function apriModal(header, messaggio, callback, conferma) {
var re = new RegExp("</?\w+\s+[^>]*>");
$("#modalHeaderTitle").text(header);
if (messaggio.match(re)) {
$("#modalBodyText").html(messaggio);
}
else {
$("#modalBodyText").html("<p>" + messaggio + "</p>");
}
(!conferma) ? $("#modalConfirm").hide() : $("#modalConfirm").show();
$("#finestraModal").modal('show')
$("#modalConfirm").off().click(function () {
if (conferma) {
$("#finestraModal").modal('hide')
conferma();
}
});
$("#modalClose").show();
$("#modalClose").off().click(function () {
if (callback) {
callback();
}
$("#finestraModal").modal('hide');
});
}
Run Code Online (Sandbox Code Playgroud)
这是一个小例子:http://jsfiddle.net/thetom/nqNzr/15/
如果您需要更多信息请询问.非常感谢你提前!