It does not work.
#include<stdio.h>
void bubble_sort(int m, int a[100000]);
void main()
{
int a[100000], i, m;
FILE * be;
be=fopen("be.txt","r");
// IMPORTANT! i pressed enter after last number in be.txt!!!
for (i=0; !(feof(be)); ++i)
fscanf(be,"%i", a+i);
m=i-1;
bubble_sort(m ,a);
fclose(be);
}
void bubble_sort(int m, int a[100000])
{
int i, ok, v, n=m;;
for (;!ok;ok=1)
{
ok=0;
for (i=0;i<=m-1;++i)
{
if (*(a+i)>*(a+i+1)) { v=*(a+i); *(a+i)=*(a+i+1); *(a+i+1)=v; ok=0;}
}
m=m-1;
}
for (i=0; i<n; ++i)
printf("%i ", a[i]);
}
The pseudo code: (I think it`s right)
Bubblesort2( A )
m:=length( A ) - 1
repeat
OK := true
for i := 0 to m-1 do
if Ai > Ai+1 then
Ai <=>Ai+1
OK := false
m := m - 1
until OK