aboutsummaryrefslogtreecommitdiff
path: root/tests/sysy_lvX/ls_copy.sy
blob: e229ef517fe14bc86ddbd8caf2da9d66cf62d3a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
int linearSearch(int haystack[], int len, int needle){
    int i = 0;
    while(i < len){
        if(haystack[i] == needle){
            return i;
        }else{
            i = i + 1;
        }
    }
    return -1;
}

int main(){
    int haystack[100];
    int pos, len;
    int needle;
    len = getarray(haystack);
    needle = getint();
    pos = linearSearch(haystack, len, needle);
    putint(pos);
    return 0;
}