//函数查找 template <class T> int seqSearch(const T list[], int n, const T &key) { for (int i = 0; i < n; i++) { if (list[i] == key) return i; } return -1; } //折半查找法 template <class T> int binSearch(const T list[], int n, const T &key) { int low = 0; int high = n - 1; while (low <= high) { int mid = (low + high) / 2; if (key == list[mid]) return mid; else if (key < list[mid]) high = mid - 1; else low = mid + 1; } return -1; }
怕什么真理无穷,进一寸有一寸的欢喜。---胡适