浙江大學(xué) mooc 數(shù)據(jù)結(jié)構(gòu) 學(xué)習(xí)記錄
1.1.1 關(guān)于數(shù)據(jù)組織
1.1.1數(shù)據(jù)組織
1.1.2空間使用
1.1.3算法效率
1.1.4抽象數(shù)據(jù)類型
1.2.1 算法定義
1.2.2 什么是好算法
1.2.3 復(fù)雜度漸進(jìn)表示
1.3 應(yīng)用實(shí)例
printN.c
#include<stdlib.h>
#include<stdio.h>
void PrintN1( int N);
void PrintN2( int N);
int main(){
int N=100000;
//遞歸 空間使用太大 N= 太大會(huì)爆掉
// PrintN1(N);
PrintN2(N);
return 0;
}
void PrintN1( int N){
for( int i=0 ; i<N; i++){
printf("%d\n", i) ;
}
return ;
}
void PrintN2( int N){
if(N){
PrintN2(N-1);
printf("%d\n",N);
}
return ;
}
時(shí)鐘打點(diǎn)
/*
* @Descripttion:
* @version: v_1.0.0
* @Author: Mailor
* @Email: xiaolele19980118@163.com
* @Date: 2020-12-17 21:58:23
* @LastEditors: Mailor
* @LastEditTime: 2020-12-17 22:04:38
*/
#include<stdio.h>
#include<stdlib.h>
#include <time.h>
clock_t start, stop;
double duration ;
void MyFunction();
int main(){
start = clock();
MyFunction();
stop = clock();
duration = ((double) (stop - start))/CLOCKS_PER_SEC ;
printf("%f \n",duration) ;
return 0 ;
}
void MyFunction(){
for(int i=0;i<10000;i++){
printf("%d \n",i);
}
}
多項(xiàng)式值計(jì)算
/*
* @Descripttion:
* @version: v_1.0.0
* @Author: Mailor
* @Email: xiaolele19980118@163.com
* @Date: 2020-12-17 22:06:52
* @LastEditors: Mailor
* @LastEditTime: 2020-12-17 23:07:09
*/
#include <stdio.h>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#define MAXN 10
#define MAX_K 1e6
clock_t start, stop ;
double duration ;
//多項(xiàng)式最大項(xiàng) 即多項(xiàng)式階數(shù)+1
double f(int n ,double a[], double x);
// double f2(int n ,double a[], double x);
void runTime(double(*f)(int , double * , double ), int n ,double a[], double x, int funcN);
double * init();
int main(){
double *p ;
p=init();
// printf("%f",p[1]);
// printf("%f",*(p+1));
runTime(f,MAXN-1,p,1.1,1);
runTime(f,MAXN-1,p, 2.2,2);
return 0;
}
double * init(){
//初始化
static double a[MAXN]; //多項(xiàng)式的系數(shù)
for (int i=0; i<MAXN;i++){
a[i] = (double)i;
}
return a;
}
double f(int n , double a[], double x){
double p ;
for(int i = n;i>0; i--){
p = a[i-1] + p*x;
}
return p ;
}
void runTime(double(*f)(int , double *, double ), int n ,double a[], double x ,int funcN){
start = clock();
for(int i=0; i<MAX_K;i++){
f(n,a,x);
}
stop = clock();
double duration = ((double)(stop - start)) / CLOCKS_PER_SEC /MAX_K;
printf("ticks%d= %f\n" ,funcN,(double)(stop - start)/MAX_K);
printf("duration = %6.2e\n", duration);
return ;
}