小数据完美,大数据错误:一个奇怪的冒泡排序问题

我正在写一个冒泡排序程序。 我使用TCC(http://bellard.org/tcc/)。我在程序中使用长长变量,因为输入数据非常大。 我的问题是:当输入数据的数量很小(例如10)时,我的程序运行得很好。 但是当输入数据的数量很大(例如5814)时,我的程序运行错误。

=========================================
我的代码和输入数据文件在这里:
https://skydrive.live.com/?cid=bfe8af46e42e3ecf&sc=documents&uc=4&id=BFE8AF46E42E3ECF!935
=========================================

这是我的程序和测试数据:

/*bubble.c*/ #include  int main() { int n,i,j; long long t, a[6001]; /*Change this to a[10000], then it works perfectly*/ freopen("data.in.txt","r",stdin); freopen("date.out.txt","w",stdout); scanf("%d",&n); /*Read input data from "data.in.txt"*/ for (i=1;i<=n;i++) { scanf("%lld",&a[i]); /*printf("i=%d\ta[i]=%lld\n",i,a[i]);*/ } /*Bubble Sort*/ for (i=1;i=i+1;j=j-1) { if (a[j]<a[j-1]) { t=a[j]; a[j]=a[j-1]; a[j-1]=t; } } } /*Output data to "data.out.txt"*/ for (i=1;i<=n;i++) { printf("i=%d\ta[i]=%lld\n",i,a[i]); } /*printf("Time used =%lf\n",(double)clock() / CLOCKS_PER_SEC);*/ /*system("pause");*/ return 0; } 

=================================

我的输入数据:非常大的数字。

5814

209442427 1519418927 828028199 47874386 1918308053 665370647 355436872 122922452 1361311685 1711685536 1850886562 752723777 567058321 1879534287 579940183 1802179021 2004892116 1219034394 269237342 410745567 849113437 ……

我刚刚下载了你的文件,并用GCC 4.1.2和TCC 0.9.24编译它,你的程序适用于两个编译器。 输出与right.date.out.txt匹配,因此您的代码是正确的。 也许您的环境中有其他东西导致编译或运行程序时出现问题。