加密算法:插入排序算法



插入排序算法代码:
# <stdlib.h>
# <stdio.h>
# <time.h>
# MAX_LENGTH 100
/*Show usage*/
void usage(char * prog)
{
prf(\"%s Usage:\\n\", prog);
prf(\"%s <the count of numbers to sort (should be less than 100)>\\n\", prog);
}
/*Generate and initialize the list*/
* generate_list( count)
{
i;
* list;
list = ( *)malloc(count*());
(list NULL)
{
perror(\"malloc\");
NULL;
}
/*Initialize the list with egers less than 100*/
srandom((unsigned )time(NULL));
for (i = 0; i < count ; i )
list[i] = random%100;
list;
}
/*Show the list*/
void show_list( * list, length)
{
i;
for(i = 0; i < length; i )
prf(\"%d \", list[i]);
prf(\"\\n\");
}
/*algorithm*/
void insert_sort( * list, length)
{
i, j, temp;
for(i = 1; i < length; i )
{
temp = list[i];
j = i - 1;
while((list[j] > temp)&&(j >= 0))
{
list[j+1] = list[j];
j --;
}
list[j+1] = temp;
show_list(list, length);
}
}
[Page] ( argc, char * argv)
{
length;
* list = NULL;
/*Deal with the arguments*/
(argc != 2)
{
usage(argv[0]);
exit(127);
}
length = atoi(argv[1]);
(!length || length > MAX_LENGTH)
{
usage(argv[0]);
exit(129);
}
list = generate_list(length);
(list NULL)
exit(128);

{
show_list(list, length);
insert_sort(list, length);


}
free(list);
1;
}


Tags:  rsa算法 排序算法 算法导论 加密算法

延伸阅读

最新评论

发表评论