Dear friends, after I use GetTickCount(), an error is output. Please ask for help. A screenshot is attached below. Many thanks!
#include<iostream>
#include<windows.h>
#include<fstream>
using namespace std;
ifstream infile("test.txt");
int main()
{
int n,i=1,j,a[100000];
DWORD time1,time2;
while(!infile.eof()) infile>>a[i++];
n=i-1;
time1=GetTickCount();
for(i=1;i<n;i++)
for(j=1;j<n;j++)
if(a[j]<a[j+1])
swap(a[j],a[j+1]); //冒泡排序
time2=GetTickCount();
cout<<time1-time2<<endl;
return 0;
}
Sometimes the result will still be 0. When I was debugging, I saw that the penultimate step was still correct, but the final output result was wrong. . . Please help me, thank you very much