int main(int argc, char *argv[]) { int a[5] = {4,2,1,5,9}; BubbleSort1(a,5); // BubbleSort2(a,5); // BubbleSort3(a,5); for(auto &t : a) std::cout << t << " " << std::endl; return 0; }
int main(int argc, char * argv[]) { int numOfLists, sizeOfLists, i, j, bufferItem; double bubBest1, bubWorst1, bubAvg1, bubBest2, bubWorst2, bubAvg2, bubBest3, bubWorst3, bubAvg3, sum1, sum2, sum3; List Lists[1000]; List bufferList; clock_t start1,end1, start2, end2, start3, end3; srand(time(NULL)); if ((argc < 3) || (argc > 3)) { /*Checks preconditions for program*/ printf("**Invalid number of arguments to run program**\n\n**Program will terminate now\n"); return 1; } numOfLists = atoi(argv[1]); sizeOfLists = atoi(argv[2]); /*only lists of size 1000 and up to 1000 lists are supported*/ if ((numOfLists>1000) || (numOfLists<=2) || (sizeOfLists>1000) || (sizeOfLists<=2)) { printf("**Invalid integer entered**\nOnly integers between 3 and 1000 are allowed\nProgram will terminate now\n"); return 1; } Initialize(&bufferList); for (i=0; i<sizeOfLists; i++) { /*Create two mandatory Lists*/ Insert(i+1, i, &Lists[0]); Insert(sizeOfLists-i, i, &Lists[1]); } for (i=2; i<numOfLists; i++) { for (j=0; j<sizeOfLists; j++) { bufferItem = (rand() %343+1); /*Create random lists*/ Insert(bufferItem, bufferList.size, &bufferList); } Lists[i] = bufferList; Initialize(&bufferList); } sum1=0; bubAvg1 = 0; start1 = clock(); /*Starts Timer*/ BubbleSort1(Lists[0]); end1 = clock(); bubBest1 = (double)(end1-start1)/CLOCKS_PER_SEC; start2 = clock(); BubbleSort1(Lists[1]); end2 = clock(); bubWorst1 = (double)(end2-start2)/CLOCKS_PER_SEC; for (i=0; i<numOfLists; i++) { start3 = clock(); BubbleSort1(Lists[i]); end3 = clock(); sum1 = ((double)(end3-start3)/CLOCKS_PER_SEC); bubAvg1 = bubAvg1 + sum1; /*Finds the Average*/ } bubAvg1 = bubAvg1/numOfLists; printf("\nBubbleSort1\n%f\n%f\n%f\n", bubBest1, bubAvg1, bubWorst1); sum2=0; bubAvg2 = 0; start1 = clock(); BubbleSort2(Lists[0]); end1 = clock(); bubBest2 = (double)(end1-start1)/CLOCKS_PER_SEC; start2 = clock(); BubbleSort2(Lists[1]); end2 = clock(); bubWorst2 = (double)(end2-start2)/CLOCKS_PER_SEC; for (i=0; i<numOfLists; i++) { start3 = clock(); BubbleSort2(Lists[i]); end3 = clock(); sum2 = ((double)(end3-start3)/CLOCKS_PER_SEC); bubAvg2 = bubAvg2 + sum2; } bubAvg2 = bubAvg2/numOfLists; printf("\nBubbleSort2\n%f\n%f\n%f\n", bubBest2, bubAvg2, bubWorst2); sum3=0; bubAvg3 = 0; start1 = clock(); MergeSort(&Lists[0], 0, Lists[0].size-1); end1 = clock(); bubBest3 = (double)(end1-start1)/CLOCKS_PER_SEC; start2 = clock(); MergeSort(&Lists[1], 0, Lists[1].size-1); end2 = clock(); bubWorst3 = (double)(end2-start2)/CLOCKS_PER_SEC; for (i=0; i<numOfLists; i++) { start3 = clock(); MergeSort(&Lists[i], 0, Lists[i].size-1); end3 = clock(); sum3 = ((double)(end3-start3)/CLOCKS_PER_SEC); bubAvg3 = bubAvg3 + sum3; } bubAvg3 = bubAvg3/numOfLists; printf("\nMergeSort\n%f\n%f\n%f\n", bubBest3, bubAvg3, bubWorst3); return EXIT_SUCCESS; }
//此时电机比656多两个脉冲,即相当于658nm的681脉冲处 BOOLEAN swgCal656nm(void) { int i,j; INT16U twd,wdMax=0; INT16U tbWd[NUM_OF_FILT]; //INT16U tb656nm[5]; swgFindUpEdge(); //找到了零级的上升沿 j = 0; //找最大值 while(1) { for(i=0;i<NUM_OF_FILT;i++) { tbWd[i]=ReadDataCfgReg(0x91,0x01); utDelay1ms(20); } twd = BubbleSort1(tbWd,NUM_OF_FILT,NUM_OF_RMV); ++j; utPrt("@%d:%x\n",j,twd); sprintf(str,"@%d:%x\n",j,twd); //utPtn1(str); if(twd<wdMax) { utPrt("begin@%d:%x\n",j,twd); sprintf(str,"begin@%d:%x\n",j,twd); //utPtn1(str); if(twd<VT_MAX) { //最大值出错,从头再找 sprintf(str,"tw=%x\n",twd); //sprintf(str,"begin@%d:%x\n",j,twd); //utPtn1(str); showStr(); swgFindUpEdge(); continue; } break; } else { wdMax = twd; //保留最大值 motor (); //继续转 } } #if 0 //为了测试空气的sig for(i=0;i<200;i++) //把大约前200去掉 { motor (); utDelay1ms (4); } setAD16Amp (2); //14位, 8倍 utDelay1ms (100); //等待数据稳定 for(i=200;i<700;i++) { dat=ReadDataCfgReg(0x91,0x01); dat1=ReadDataCfgReg(0x93,0x01); utPrt("%x,%x,%d\n",dat,dat1,i); motor(); utDelay1ms(100); } while(1) { LAMP_TOG; utDelay1ms(200); } #endif //找到最高点了,前前一个是最高点,本点是第2点 //for(i=0;i<681;i++) //680 for(i=0;i<671;i++) //680 { motor (); utDelay1ms (2); } //数字太小了,要放大8倍来看 //WriteDataCfgReg(0x90,0x07); setADRefBitsAmp (14, 8); //14位, 8倍 utDelay1ms (20); //等待数据稳定 //开始683点 //找此时的极值 pMaxRef = 0; maxRef = 0; for(j=0;j<MAX_656SCAN;j++) //675-690,5 { for(i=0;i<NUM_OF_FILT;i++) { tbWd[i]=ReadDataCfgReg(0x91,0x01); utDelay1ms(20); } motor (); //转到下一个 twd = BubbleSort1(tbWd,NUM_OF_FILT,NUM_OF_RMV); if(twd>maxRef) { maxRef = twd; pMaxRef = j; } //tb656nm[j] = twd; utPrt("%x,%d\n",twd,j); sprintf(str,"%x,%d\n",twd,j); //utPtn1(str); utDelay1ms(40); //等待100ms稳定 } sprintf(str,"max=%x,%d\n\n",maxRef,pMaxRef); //utPtn1(str); utPtn(str); //if(tb656nm[2]<0x0400) if(maxRef<VT_MAX656) { sprintf(str,"656=%x",maxRef); showStr(); return false; } if((pMaxRef==0)||(pMaxRef==(MAX_656SCAN-1))) { sprintf(str,"maxref=%x",pMaxRef); showStr(); return false; } curStep = 679+(MAX_656SCAN-1-pMaxRef); //679对应656nm //定位OK utPtn("location 656 ok!\n"); //回到16位,固定下来放大两倍 //WriteDataCfgReg(0x90,0x0D); //0D->16位,放大2倍 setAD16Amp(2); utDelay1ms(20); return true; }