Leroz 2015-06-06 03:45 采纳率: 0%
浏览 1530

新人求助!记录程序时间出错

#include
#include
#include
#include"sort.h"
using namespace std;
int main()
{
int choice, n, i, j;
DWORD start, end;
while(1)
{
cout << "输入数据的方式:" << endl;
cout << "1、手动输入" << endl;
cout << "2、系统自动产生" << endl;
cout << "输入方式序号:" << endl;
cin >> choice;

    if (choice == 1)
    {
        cout << "排序的元素个数:" << endl;
        cin >> n;
        int *a = new int[n];
        int *b = new int[n];
        int *temp = new int[n];
        cout << "要排序的元素:" << endl;

        for (i = 0; i < n; i++)
        {
            cin >> a[i];
            b[i] = a[i];
        }

        cout << "快排结果:" << endl;
        Quicksort(a, 0, n - 1);

        for (i = 0; i < n; i++)
            cout << a[i] << " ";

        cout << endl;
        cout << "归并结果:" << endl;
        Mergesort(b, 0, n - 1);

        for (i = 0; i < n; i++)
            cout << b[i] << " ";

        cout << endl;
    }

    else if (choice == 2)
    {
        cout << "下面将随机产生10组数据:" << endl;
        for (i = 1; i <= 10; i++)
        {   
            cout << "#" << i << endl;
            int *a = new int[10000 * i];
            int *b = new int[10000 * i];
            int *temp = new int[10000 * i ];

            for (j = 0; j < 10000 * i; j++)
            {
                a[j] = rand() % 100000;
                b[j] = a[j];
            }

            start = GetTickCount();
            Quicksort(a, 0, 10000 * i - 1);
            end = GetTickCount();
            cout << "快速排时间:" << end - start << "ms" << endl;
            start = GetTickCount();
            Mergesort(b, 0, 10000 * i - 1);
            end = GetTickCount();
            cout << "归并排时间:" << end - start << "ms" << endl;
        }
    }
    else
        break;
}
system("pause");
return 0;

程序中choice==1是用来测试两个排序算法有没有正确排序的,经测没问题,可是到随机生成后就有问题了,输出的时间很不对劲...


另外,别人的程序在自己电脑上没问题,到我的电脑就出现同样问题了!!!!!

图片补在下面
  • 写回答

4条回答

  • Leroz 2015-06-06 03:50
    关注

    图片说明

    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料