- 博客(11)
- 资源 (6)
- 收藏
- 关注
原创 判断回文串
/// /// 判断是否为回文串/// /// 需要判断的字符串/// True是回文串,False不是回文串public static bool IsPalindrome(string str){ string temp = new string(str.Reverse().ToArray()); return temp == str;}
2012-12-26 23:52:32 703
原创 希尔排序
/// /// 希尔排序/// /// 需要排序的数组public static void ShellSort(int[] array){ int i, j, temp, length = array.Length, gap = length >> 2; for (; gap > 0; gap >>= 2) { for (i = gap; i <
2012-12-26 23:31:59 352
原创 选择排序
/// /// 选择排序/// /// 需要排序的数组public static void SelectSort(int[] array){ int min;// 当前剩余数组的最小数的下标 for (int i = 0; i < array.Length; i++) { min = i; #region 查找数组中剩余的最小值的下
2012-12-26 21:52:20 354
原创 归并排序
/// /// 归并排序/// /// 已排序的第一个数组/// 已排序的第二个数组/// 合并后的数组public static int[] MergeSort(int[] a, int[] b){ int[] result = new int[a.Length + b.Length];// 合并后的数组 int aIndex = 0, bIndex = 0;//
2012-12-26 12:06:25 375
原创 快速排序
public static void QSort(int[] array, int low, int high){ int left = low; int right = high; int pivotkey = array[left]; while (left < right) { while (left = pivotkey)
2012-12-24 11:34:10 339
原创 双向冒泡排序
/// /// 双向冒泡排序/// /// 需要排序的数组public static void TwoWayBubbleSort(int[] array){ int maxindex = array.Length - 1, left = 0, right = maxindex, i;// maxindex为数组最大下标,left为左游标,right为右游标 while (
2012-12-20 11:41:25 413
原创 二分查找
/// /// 二分查找/// /// 需要查找的数组/// 需要查找的元素/// 若查找成功,则返回该元素在数组的下标,查找不到返回-1public static int BinarySearch(int[] array, int key){ int low = 0, high = array.Length - 1, mid; while (low <= high)
2012-12-20 11:12:19 372
原创 判断一个数是否为质数
/// /// 判断一个大于等于2的整数是否为质数/// /// True是质数,False不是质数public static bool IsPrime(int n){ if ((n & 1) == 0)// 等价于n%2==0 { return false; } int sqrn = (int)Math.Sqrt(n);// 求n的开方,
2012-12-20 10:03:39 769
原创 求最大公约数
/// /// 使用Stein算法求最大公约数 /// public static int Gcd(int a, int b) { int k = 0;// 记录两原数为2的多少倍。原理:Gcd(ka,kb)==k*Gcd(a,b)。 for (; ; ) {
2012-12-19 23:53:10 413
原创 求斐波那契数列第n项
/// /// 公式法求斐波那契数列/// public static int Fibonacci(int n){ double sqr5 = Math.Sqrt(5) * 0.5; return (int)((Math.Pow(0.5 + sqr5, n) - Math.Pow(0.5 - sqr5, n)) / sqr5 * 0.5);}/// /// 循环法求斐波
2012-12-12 15:05:29 752
转载 c# 获取鼠标对于屏幕的位置
需要调用win32api,winform、wpf通用[DllImport("user32.dll")]public static extern bool GetCursorPos(out POINT lpPoint);[StructLayout(LayoutKind.Sequential)]public struct POINT{ public int X; publ
2012-12-06 22:37:18 3092
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人