private static void QuictSort(int[] zu, int left, int right) { if (left < right) { int i = 0; int j = right - 1; int mid = zu[(left + right) / 2]; while (true) { while (i<right && zu[i]<mid) { i++; } while (j > left && zu[j] > mid) { j--; } if (i == j) { break; } int temp = zu[i]; zu[i] = zu[j]; zu[j] = temp; if (zu[i] == zu[j]) { j--; } } QuictSort(zu, left, i); QuictSort(zu, i + 1, right); } }
// 拉格朗日插值查找 private static int LChaZhao(int[] zu, int key) { int left = 0; int right = zu.Length - 1; int middle = -1; while (left <= right) { middle = left + (right - left) * (key - zu[left]) / (zu[right] - zu[left]); if (key == zu[middle]) { return middle; } else if (key > zu[middle]) { left = middle + 1; } else { right = middle - 1; } } return -1; }
原文地址:https://www.cnblogs.com/zhaodadan/p/9963448.html
时间: 2024-12-08 08:10:25