Monthly Archives: August 2009

A better one

int hourMinuteHandInRight = 0; int hourMinuteHandInLeft = 0; int interval = 60; int rightHand = 180 – interval; int leftHand = 540 – interval; while (hourMinuteHandInRight < 12 && hourMinuteHandInLeft < 12) { rightHand += interval; if (rightHand == 660) … Continue reading

Posted in Uncategorized | Leave a comment

Write a function to give out all the time (hour:minute) that the angle between minute hand and hour hand on a clock is 90 degree.

static void Main(string[] args) { for (int h = 0; h < 12; h++) { double m = 1.0; double angle = 1.0 if (h < 9) { m = 1.0*(60 * h + 180) / 11; angle = (m … Continue reading

Posted in 计算机与 Internet | Leave a comment

Traverse binary tree not recursively

       public static void PreOrder<T>(BinaryTreeNode<T> root, Action<BinaryTreeNode<T>> action)        {            if (root == null)            {                return;            }             Stack<BinaryTreeNode<T>> stack = new Stack<BinaryTreeNode<T>>();            stack.Push(root);            while (stack.Count != 0)            {                BinaryTreeNode<T> current = stack.Pop();                if (current != null)                {                    action(current);                }                 … Continue reading

Posted in Uncategorized | Leave a comment

Link binary tree nodes at the same level

Given modified binary tree node public class TreeNode<T> {     public TreeNode<T> LeftChild;     public TreeNode<T> RightChild;     public TreeNode<T> Right; }         public static void LinkEachLevel<T>(TreeNode<T> root)        {            LinkedList<TreeNode<T>> rightMost = new LinkedList<TreeNode<T>>();            LinkedListNode<TreeNode<T>> first = new LinkedListNode<TreeNode<T>>(null);            rightMost.AddFirst(first);            … Continue reading

Posted in Computers and Internet | Leave a comment