edited by
942 views
1 votes
1 votes

Consider the following C code:

int getNextGap(int gap){
    gap=(gap*10)/13;
    if(gap<1)return 1;
    return gap;
}
void mystery(int a[ ],int n){
    int gap=n;
    bool red=true;
    while(gap!=1||red==true){
        gap=getNextGap(gap);
        red=false;
        for(int i=0;i<(n-gap);i++){
            if(a[i]>a[i+gap]){
                swap(a[i],a[i+gap]);
                red=true;
            }
        }
    }
}

The array $A=\left \{ 9,4,-1,3,5,7,99,-33,104 \right \}$ passed in the above function , and n is number of array elements, then what output  will print at last?


I mostly stuck how bool function working here. Plz help me out, how program executing:(

edited by

Please log in or register to answer this question.

Related questions

4 votes
4 votes
3 answers
2
2 votes
2 votes
2 answers
4
srestha asked May 12, 2019
1,075 views
Consider the following function $foo()$void foo(int n){ if(n<=0) printf("Bye"); else{ printf("Hi"); foo(n-3); printf("Hi"); foo(n-1); } }Let $P(n)$ represent recurrence r...