sorting array of struct by id
<p>I take an array of record as case study in my Graduation Project.  In the code I've written, I made an array of the structure and entered the id of the structs in an array 
of int to make the sorting easier but when it runs it gets stuck.</p>

<pre><code>#include&lt;iostream.h&gt;
struct book{
    char Bname[8], Bsubject[8];
    int copyies, Bid, Bfound;
} a[100];

void Ider(book a[],int r[],int index){
    for(int i=0;i&lt;index;i++)
        r[i]=a[i].Bid;
}

void swap(int &amp;a,int &amp;b){
    int c=a;
    a=b;
    b=c;
}

void Bublesort(int a[],int n){
   for(int j=0;j&lt;n;j++)
    for(int i=1;i&lt;n-1;i++)
        if(a[i]&gt;a[i+1])
            swap(a[i+1],a[i]);                
}

int bsearch(int b[],int key,int first,int last){
    int  midel=(first+last)/2;
    for(int i=0;i&lt;last;i++){
        if(b[midel]==key)
            return midel;
        else 
            if(b[midel]&gt;key)
                return bsearch(b,key,first,midel-1);
            else 
                if(b[midel]&lt;key)
                    return bsearch(b,key,midel+1,last);
    }
}

int main(){

    int r,i, index=0,m[100];
    char ch;

    do{
        cout&lt;&lt;"Enter your"&lt;&lt;index+1&lt;&lt;" Book id"&lt;&lt;"    ";
        cout&lt;&lt;endl;
        cin&gt;&gt;a[index].Bid;
        cout&lt;&lt;"Enter your"&lt;&lt;index+1&lt;&lt;" Book name"&lt;&lt;"    ";
        cout&lt;&lt;endl;

         cin&gt;&gt;a[index].Bname;

         cout&lt;&lt;"Enter your"&lt;&lt;index+1&lt;&lt;" Book subject"&lt;&lt;"    ";
         cout&lt;&lt;endl;

         cin&gt;&gt;a[index].Bsubject;
         index++;
         a[index].Bfound++;
         a[index].copyies++;
         if(index==99)
             break;

    quite : cout&lt;&lt;"Do you want to continue";
         cin&gt;&gt;ch;

    } while(ch=='y');

    Ider(a,m,index);
    Bublesort(m,index);

    char p;

    do{
        cout&lt;&lt;"Do you want to search?"&lt;&lt;endl;
        cin&gt;&gt;p;
        cout&lt;&lt;"enter your id";
        cin&gt;&gt;i; 
        r=bsearch(m,i,0,index);
        cout&lt;&lt;a[r].Bfound&lt;&lt;"          ";

    } while(ch=='y');

    system("pause");
    return 0;
}
</code></pre>

<p>When it reaches <code>bublesort()</code> it hangs and didn't give any output, but why?</p>
