public class RedBlackBST<TKey, TValue> { private Node root; public int redCount = 0; public int totalNodes = 0; private static Boolean RED = true; private static Boolean BLACK = false; private class Node { . . . . . . private Node put(Node h, TKey key, TValue val) { if (h == null) // Do standard insert, with red link to parent. { return new Node(key, val, 1, RED); } int cmp = key.compareTo(h.key); //This is where I get stuck if (cmp < 0) { h.left = put(h.left, key, val); } else if (cmp > 0) { h.right = put(h.right, key, val); } else { h.val = val; } if (isRed(h.right) && !isRed(h.left)) { h = rotateLeft(h); } if (isRed(h.left) && isRed(h.left.left)) { h = rotateRight(h); } if (isRed(h.left) && isRed(h.right)) { flipColors(h); } h.N = size(h.left) + size(h.right) + 1; return h; }
public class RedBlackBST<TKey, TValue> where TKey: IComparable { ... }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)