optimization of this algorithm?

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
void teest(int *prm1, int prm2)
{
  int m, n, tmp, flg;
  for(m=prm2-1; m>0; --m)
  {
    flg = 0;
    n=0;

    while(n<m)
    {
      if ( prm1[n] > prm1[n+1])
      {
        tmp = prm1[n];
        prm1[n] = prm1[n+1];
        prm1[n+1]= tmp;
        flg=1;
      }
      ++n;
    }

    if (!flg)
      break;
  }
}


as you can see there is already the optimization of the flag ..
Do you think that there is sth else that could make that algorithm (Bubble sort) better and faster? is there another better optimization?

thanks again :)
Topic archived. No new replies allowed.