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

📄 insertion.c

📁 implementation of insertion sort algorithm and its computational cost. it is testing on arrays of le
💻 C
字号:
#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 arreglosrand(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;}

⌨️ 快捷键说明

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