锘??xml version="1.0" encoding="utf-8" standalone="yes"?>精品国内亚洲2022精品成人 ,最新av免费在线,久久精品一区四区http://www.aygfsteel.com/coolflyreg/category/25433.htmlzh-cnFri, 31 Aug 2007 02:11:13 GMTFri, 31 Aug 2007 02:11:13 GMT60[綆楁硶]浜屽弶鏍慬杞琞http://www.aygfsteel.com/coolflyreg/archive/2007/08/31/141622.htmlcoolflyr_regcoolflyr_regFri, 31 Aug 2007 01:37:00 GMThttp://www.aygfsteel.com/coolflyreg/archive/2007/08/31/141622.htmlhttp://www.aygfsteel.com/coolflyreg/comments/141622.htmlhttp://www.aygfsteel.com/coolflyreg/archive/2007/08/31/141622.html#Feedback0http://www.aygfsteel.com/coolflyreg/comments/commentRss/141622.htmlhttp://www.aygfsteel.com/coolflyreg/services/trackbacks/141622.html鍜?/span>鍫嗙被浼鹼紝浜屽弶鏍?/span>涔熸槸涓縐嶅緢濂囩壒鐨勬暟鎹粨鏋勩傚畠鍖呭惈浜嗘牴鑺傜偣錛岃妭鐐規渶澶氬彧鏈変竴涓乏鍙寵妭鐐廣?/span>

鐖惰妭鐐瑰拰宸﹀彸瀛愯妭鐐逛箣闂存湁涓瀹氱殑鍏崇郴錛?br /> 1. 鐖惰妭鐐規瘮宸﹁妭鐐瑰ぇ錛堝皬錛夈?br /> 2. 鐖惰妭鐐規瘮鍙寵妭鐐瑰皬錛堝ぇ錛夈?/span>

閫氳繃榪欑鐗規э紝浜屽弶鏍戠殑鏌ユ壘瀹氫綅闈炲父鏂逛究錛屾瘮鏁扮粍銆侀摼琛ㄧ殑鏌ユ壘鏁堢巼瑕侀珮寰堝銆傚湪鎴戠殑鏈哄櫒涓婏紝浠?00涓囦釜闅忔満鏁存暟涓煡鎵句竴涓暣鏁板鉤鍧囬渶瑕?.00386姣銆傚彲瑙佹晥鐜囩‘瀹炲緢楂樸?/span>

涓嶈繃錛屼簩嬈℃爲鏈変竴涓嚧鍛界殑緙虹偣錛氬鏋滄彃鍏ョ殑鏁版槸緇忚繃鎺掑簭鐨勶紝鍒欎細浣夸簩嬈℃爲楂樺害闈炲父澶э紝灝辯瓑鍚屼簬綰挎ф暟緇勪簡錛屼粠鑰屾瀬澶у獎鍝嶄簡鏌ユ壘鍜屾彃鍏ョ殑鏁堢巼銆?/span>

涓嬮潰鏄簩鍙夋爲鐨凧ava瀹炵幇浠g爜銆?/span>

package cn.tenyears.demo;

import java.util.Comparator;

/**
 * Binary Tree
 
 @author taolue
 
 */
public class BinTree<T> {

  /**
   * 鏍戣妭鐐?/font>  
   */
  public class Node {
    private T data;

    private Node left;

    private Node right;

    public void setData(T data) {
      this.data = data;
    }

    public void setLeft(Node left) {
      this.left = left;
    }

    public void setRight(Node right) {
      this.right = right;
    }

    public Node getLeft() {
      return this.left;
    }

    public Node getRight() {
      return this.right;
    }

    public T getData() {
      return this.data;
    }

    public Node(T data, Node l, Node r) {
      this.data = data;
      this.left = l;
      this.right = r;
    }
  }

  class ParentAndChild {

    public Node parent = null;

    public Node child = null;

    public ParentAndChild(Node p, Node c) {
      this.parent = p;
      this.child = c;
    }
  }

  private Comparator<T> comparator = null;;

  public final ParentAndChild NONE_PC = new ParentAndChild(null, null);

  private Node root = null;

  private int treeSize = 0;

  public BinTree(Comparator<T> comparator) {
    this.comparator = comparator;
  }

  public Node search(T data) {
    return searchPC(data).child;
  }

  public void insert(T data) {
    Node temp = root;
    Node parent = null;
    int equal = 0;
    while (temp != null) {
      parent = temp;
      equal = comparator.compare(data, temp.getData());
      if (equal < 0)
        temp = temp.getLeft();
      else
        temp = temp.getRight();
    }
    Node one = new Node(data, null, null);
    if (parent == null)
      root = one;
    else if (comparator.compare(data, parent.getData()) 0)
      parent.setLeft(one);
    else
      parent.setRight(one);
    this.treeSize++;
  }

  public boolean delete(T data) {
    Node deleted = null;
    Node parent = null;
    Node right = null;
    ParentAndChild pc = this.searchPC(data);
    deleted = pc.child;
    parent = pc.parent;
    if (deleted == null)
      return false;
    if (deleted.getRight() == null)
      right = deleted.getLeft();
    else if (deleted.getLeft() == null)
      right = deleted.getRight();
    else {
      Node parent1 = deleted;
      right = deleted.getLeft();
      while (right.getRight() != null) {
        parent1 = right;
        right = right.getRight();
      }
      if (parent1 == deleted)
        right.setRight(deleted.getRight());
      else {
        parent1.setRight(right.getLeft());
        right.setLeft(deleted.getLeft());
        right.setRight(deleted.getRight());
      }
    }
    if (parent == null)
      root = right;
    else if (comparator.compare(deleted.getData(), parent.getData()) 0)
      parent.setLeft(right);
    else
      parent.setRight(right);
    this.treeSize--;
    return true;
  }

  public int getSize() {
    return this.treeSize;
  }

  private ParentAndChild searchPC(T data) {
    Node temp = root;
    Node parent = null;
    int equal = 0;
    while (temp != null) {
      equal = comparator.compare(data, temp.getData());
      if (equal == 0)
        break;
      else {
        parent = temp;
        if (equal < 0)
          temp = parent.getLeft();
        else
          temp = parent.getRight();
      }
    }
    if (temp != null)
      return new ParentAndChild(parent, temp);
    return this.NONE_PC;
  }

  public static void main(String[] args) {
    Comparator<Integer> com = new Comparator<Integer>() {
      public int compare(Integer o1, Integer o2) {
        return o1.compareTo(o2);
      }
    };
    BinTree<Integer> tree = new BinTree<Integer>(com);
    int size = 1000000;
    Integer[] a = new Integer[size];
    for (int i = 0; i < size; i++) {
      a[i= Integer.valueOf((intMath.round(Math.random() * size));
      tree.insert(a[i]);
    }
    long start = System.currentTimeMillis();
    // find
    for (int i = 0; i < size; i++) {
      if (tree.search(a[i]) == null)
        System.out.println("Error: Find None.");
    }
    long end = System.currentTimeMillis();
    System.out.println("Last(AVG): " (end - start1.0f / size + " ms");
  }
}


]]>
主站蜘蛛池模板: 平和县| 崇仁县| 新丰县| 鸡西市| 淮安市| 肇东市| 衡水市| 九龙县| 嘉鱼县| 瑞安市| 白玉县| 凌海市| 博白县| 安多县| 清苑县| 闸北区| 吴江市| 民县| 苍山县| 遵义市| 德庆县| 大方县| 施甸县| 陆良县| 常宁市| 阜南县| 田林县| 昌乐县| 运城市| 临潭县| 若尔盖县| 琼结县| 缙云县| 井研县| 潢川县| 平凉市| 建湖县| 伊吾县| 金坛市| 彭山县| 鸡泽县|