• PUDN用户
    了解作者
  • C/C++
    开发工具
  • 1KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 2
    下载次数
  • 2008-11-06 00:39
    上传日期
implementation of insertion sort algorithm and its computational cost. it is testing on arrays of lenghts differents
insertion.rar
  • www.pudn.com.txt
    218B
  • insertion.c
    898B
内容介绍
#include <stdio.h> #include <time.h> #include <sys/time.h> void insertion_sort(int A[],int tam) { int i,j,key; for(j=1;j<tam-1;j++) { key = A[j]; i=j-1; while(i>=0 && A[i] > key) { A[i+1] = A[i]; i=i-1; } A[i+1]=key; } } double timeval_diff(struct timeval *a, struct timeval *b) { return (double)(a->tv_sec + (double)a->tv_usec/1000000) - (double)(b->tv_sec + (double)b->tv_usec/1000000); } int main(){ struct timeval t_ini, t_fin; double secs; long i, j; int tam=30; int B[tam]; ////Generando el arreglo srand(time(NULL)); for (i = 0; i < tam; i ++) B[i]=rand()%5000; gettimeofday(&t_ini, NULL); insertion_sort(B,tam); gettimeofday(&t_fin, NULL); for(i=0;i<tam-1;i++) printf("%d =>",B[i]); printf("********************************************************\n"); secs= timeval_diff(&t_fin, &t_ini); printf("%.16g milisegundos\n", secs * 1000.0); return 0; }
评论
    相关推荐