void delete(RedBlackNode z)
    {
    	if(z == nil)
    		return;
    	
    	RedBlackNode y = z;
    	RedBlackNode x = nil;
    	boolean yOriginalColor = y.color;
    	
    	if(z.left == nil)
    	{
    		x = z.right;
    		transplant(z, z.right);
    	}
    	else if (z.right == nil)
    	{
    		x = z.left;
    		transplant(z, z.left);    		
    	}
    	else
    	{
    		y = treeMinimum(z.right);
    		yOriginalColor = y.color;
    		x = y.right;
    		
    		if(y.parent == z)
    			x.parent = y;
    		else
    		{
    			transplant(y, y.right);
    			y.right = z.right;
    			y.right.parent = y;
    		}
    		
    		transplant(z,y);
    		y.left = z.left;
    		y.left.parent = y;
    		y.color = z.color;
    	}
    	
    	if(yOriginalColor == BLACK)
    		deleteFixUp(x);
    }