⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 p25.cpp

📁 包含常见的数据结构的类和函数
💻 CPP
字号:
int SeqSearch ( int a[], const int n, const int x ) {    int i = 0;    while ( i < n && a[i] != x ) i++;    if ( i == n ) return -1;    return i;}#include <iostream.h>#include <time.h>void TimeSearch() {    int a[1001], n[20];    /*const*/ long r[20]; /*= {3000000,3000000,3000000,3000000,1000000,1000000,800000,	800000,500000,500000,250000,150000,100000,75000,70000,60000,50000,50000};*/    for ( int i=0; i < 20; i++ ) r[i]=500000;    for ( int j=1; j <= 1000; j++ ) a[j] = j;    for ( j = 0; j < 10; j++ ) {	n[j] = 10*j; n[j+10] = 100*(j+1);    }    cout << " n  totalTime  runTime" << endl;    for ( j = 0; j < 20; j++) {       long start, stop;       time (&start);       for (long b = 1; b <= r[j]; b++ )	   int k = SeqSearch (a, n[j], 0);       time (&stop);       long totalTime = stop - start;       float runTime = (float)(totalTime)/(float)(r[j]);       cout << " " << n[j] << "  " << totalTime << "  " <<runTime << endl;    }    cout << "Times are in hundreadths of a second." << endl;}void main () {    TimeSearch();}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -