-
Notifications
You must be signed in to change notification settings - Fork 0
/
17_6.cpp
47 lines (43 loc) · 874 Bytes
/
17_6.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//
// 17_6.cpp
//
//
// Created by Pengyan Qin on 7/18/15.
//
//
#include <iostream>
using namespace std;
struct sortInd{
int start;
int end;
};
// most straight forward method
// time complexity: O(n^2)
sortInd find_index(int A[], int n){
sortInd res;
for(int i = 0; i < n; ++i){
for(int j = i + 1; j < n; ++j){
if(A[i] > A[j]){
res.start = i;
goto next;
}
}
}
next:
for(int i = n - 1; i >= 0; --i){
for(int j = i - 1; j >= 0; --j){
if(A[i] < A[j]){
res.end = i;
goto end;
}
}
}
end:
return res;
}
int main(){
int A[] = {1, 2, 4, 7, 10, 11, 7, 12, 6, 7, 16, 18, 19};
int n = 13;
sortInd res = find_index(A, n);
cout << "(" << res.start << ", " << res.end << ")" << endl;
}