算法.冒泡和二分查找

public static void SortOrder(int[] arrlist)
        {
            int temp;
            for (int i = arrlist.GetUpperBound(0); i >= 1; i--)
            {
                for (int j = 0; j < arrlist.GetUpperBound(0) - 1; j++)
                {
                    if (arrlist[j] > arrlist[j + 1])
                    {
                        temp = arrlist[j];
                        arrlist[j] = arrlist[j + 1];
                        arrlist[j + 1] = temp;
                    }

                }
            }

        }

        public static int binarySearchBad(int[] arr, int value)
        {
            int low = 0, high = arr.Length - 1;
            int middle;
            while (low <= high)
            {
                middle = (high +low) / 2;

                if (value == arr[middle])
                {
                    return middle;

                }
                if (value > arr[middle])
                {
                    low = middle + 1;
                }
                if (value < arr[middle])
                {
                    high = middle - 1;
                }
            }
            return -1;
        }

posted @ 2012-11-16 18:51  (二少)在南极  阅读(166)  评论(0编辑  收藏  举报