【作業】折半查詢法函式找17
阿新 • • 發佈:2020-12-27
#include
#include
using namespace std;
void jhy(int* p) {
int c;
int d;
for (int z = 5; z >0; --z) {
if (z < 5)
p = p - z-1;
for (int i = 0; i < z; ++i, ++p) {
c = *(p + 1);
d = *p;
if (d > c) {
*(p + 1) = d;
*p = c;
}
} } for (int d = 0; d <5; ++d) { cout << *(p + d) << endl; } for (int i = 0; i < 3; ++i) { if (*(p + 2) == 17) cout << 2; if (*(p + 2) < 17) { if (*p + 3 < 17) cout << 4; else cout << 3; } if (*(p + 2) > 17) { if (*(p + 1) > 17) cout << 1; else cout << 2; } }
}
int main() {
int a[5] = {19,67,24,11,17 };
int b[5] = { 2,3,9,17,59 };
jhy(&a[0]);
jhy(&b[0]);
return 0;
}