XG 的个人资料Life, it seems, will fad...照片日志列表更多 ![]() | 帮助 |
|
Life, it seems, will fade awaydrifting further every day 2009/8/28 A better oneint 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){ rightHand = 0; hourMinuteHandInRight++; } Console.WriteLine("{0}:{1}", hourMinuteHandInRight, (int)(rightHand / 11));hourMinuteHandInRight++; leftHand += interval; if (leftHand >= 660){ hourMinuteHandInLeft++; leftHand = 0; } Console.WriteLine("{0}:{1}", hourMinuteHandInLeft , (int)(leftHand / 11));hourMinuteHandInLeft++; } 2009/8/27 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 - h * 5 - m / 12) * 6; Console.WriteLine("{0}:{1} {2}", h, (int)m, angle);} if (h > 9){ m = 1.0 * (60 * h - 540) / 11; angle = (h * 5 + m / 12 - m) * 6; Console.WriteLine("{0}:{1} {2}", h, (int)m, angle);} if (h < 3){ m = 1.0 * (60 * h + 540) / 11; angle = (m - h * 5 - m / 12) * 6; Console.WriteLine("{0}:{1} {2}", h, (int)m, angle);} if (h > 3){ m = 1.0 * (60 * h - 180) / 11; angle = (h * 5 + m / 12 - m) * 6; Console.WriteLine("{0}:{1} {2}", h, (int)m, angle);} } } 2009/8/4 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); } if (current.RightChild != null)
{ stack.Push(current.RightChild); } if (current.LeftChild != null)
{ stack.Push(current.LeftChild); } } } public static void InOrder<T>(BinaryTreeNode<T> root, Action<BinaryTreeNode<T>> action)
{ if (root == null) { return; } Stack<BinaryTreeNode<T>> stack = new Stack<BinaryTreeNode<T>>();
BinaryTreeNode<T> current = root;
do
{ while (stack.Count != 0 && current == null) { current = stack.Pop(); action(current); current = stack.Pop(); } if (current != null)
{ stack.Push(current.RightChild); stack.Push(current); current = current.LeftChild; } } while (stack.Count != 0);
} public static void LastOrder<T>(BinaryTreeNode<T> root, Action<BinaryTreeNode<T>> action)
{ if (root == null) { return; } Stack<BinaryTreeNode<T>> stack = new Stack<BinaryTreeNode<T>>();
BinaryTreeNode<T> current = root;
do
{ if (current.HasChildren) { stack.Push(current); if (current.LeftChild != null)
{ if (current.RightChild != null) { stack.Push(current.RightChild); } current = current.LeftChild; } else { current = current.RightChild; } } else { action(current); while (stack.Count != 0 && current.IsChildrenOf(stack.Peek()))
{ current = stack.Pop(); action(current); } if (stack.Count != 0) { current = stack.Pop(); } } } while (stack.Count != 0); } Link binary tree nodes at the same levelGiven 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); LinkEachLevel(root, rightMost.First); } public static void LinkEachLevel<T>(TreeNode<T> node, LinkedListNode<TreeNode<T>> rightNode)
{ if (rightNode.Value != null) { node.Right = rightNode.Value; } rightNode.Value = node; if (rightNode.Next == null)
{ rightNode.List.AddLast(new LinkedListNode<TreeNode<T>>(null)); } if (node.RightChild != null)
{ LinkEachLevel((TreeNode<T>)node.RightChild, rightNode.Next); } if (node.LeftChild != null)
{ LinkEachLevel((TreeNode<T>)node.LeftChild, rightNode.Next); } } 2008/9/1 Reporting Services中如何对数据进行分页合计?Report services中不直接支持分页合计,实现这个功能得加些vb code(report code).
public shared Dim _rowCount As Int32=0 public Function AddToRowCount() as Int32 public Function AddToSum(ByVal quantity as Int32) as Int32 public function GetSum() as Int32 public Function GetCurrentCountAndReset() As Int32
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
|