小数据完善,大型数据错误:一个奇怪的冒泡排序的问题 [英] Small data perfect, Large data wrong: A strange bubble sort question

查看:102
本文介绍了小数据完善,大型数据错误:一个奇怪的冒泡排序的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个冒泡排序程序。
我用TCC(http://bellard.org/tcc/)。
我用很长很长的变量在我的计划,因为输入的数据是非常大的。
我的问题是:当输入数据的数量很少(e.g.10)我的计划完美。但是,当输入数据的数目是大的(例如5814)我的程序工作错误。

I'm writing a bubble sort program. I use TCC (http://bellard.org/tcc/)。 I use long long variables in my program, because the input data is very large. My problem is : When the number of input data is small (e.g.10) my program works perfectly. But when the number of input data is large (e.g 5814) my program works wrong.

=========================================
结果我的code和输入数据文件是在这里:结果
<一href=\"https://skydrive.live.com/?cid=bfe8af46e42e3ecf&sc=documents&uc=4&id=BFE8AF46E42E3ECF!935\" rel=\"nofollow\">https://skydrive.live.com/?cid=bfe8af46e42e3ecf&sc=documents&uc=4&id=BFE8AF46E42E3ECF!935
结果=========================================

=========================================
My code and input data file is here:
https://skydrive.live.com/?cid=bfe8af46e42e3ecf&sc=documents&uc=4&id=BFE8AF46E42E3ECF!935
=========================================

下面是我的程序和测试数据:

Here is my program and testing data:

/*bubble.c*/
#include <stdio.h>

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<=n-1;i=i+1) {
        for (j=n;j>=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;
}

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

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

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

My input data: Very large numbers.

5814

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

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匹配,所以你的code是正确的。也许还有别的东西在你的环境是造成问题的编译和运行程序。

I just downloaded your files and compiled it with GCC 4.1.2 and with TCC 0.9.24 and you program works fine with both compilers. The output matches right.date.out.txt, so your code is correct. Perhaps there's something else in your environment that is causing problems compiling or running your program.

这篇关于小数据完善,大型数据错误:一个奇怪的冒泡排序的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆