程序员经典面试题:数组旋转算法的代码
把做工程过程中比较常用的一些内容段做个珍藏,下面的内容内容是关于程序员经典面试题:数组旋转算法的内容。
#include<iostream>
using namespace std;
int a[1000005];
if (from == to - 1) {
return (a[from] < a[to])?a[from]:a[to];
}
if (from == to) {
return a[to];
}
int mid = (from + to) >> 1,x;
if (a[mid] < a[to]) {
x = find(a, from, mid - 1);
if (x > a[mid]) {
x = a[mid];
}
}
else if (a[mid] > a[to]) {
x = find(a,mid + 1, to);
}
else {
int x1 = find(a, from, mid - 1);
int x2 = find(a, mid + 1, to );
x = (x1 < x2)?x1:x2;
if (x > a[mid]) {
x = a[mid];
}
}
return x;
}
int main() {
int i,n;
while (scanf("%d",&n) != EOF) {
for (i = 0; i < n; ++i) {
scanf("%d", a + i);
}
printf("%dn",find(a,0,n -1));
}
return 0;
}