2013年3月17日

排序实现

摘要: 写完的时候忘了贴出来,现在一起贴好了。这个demo很简答,简单选择、插入、快排和归并,别的有时间再练习好了。供刚入门的童鞋参考吧。^_^ 1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <time.h> 4 #define N 10 5 int a[N], b[N]; 6 void init_array(int l, int r) 7 { 8 int i; 9 srand(time(NULL));10 for(i=1;i<=r;i++) a[i]=rand()%100;11 }12 void 阅读全文

posted @ 2013-03-17 12:19 xuangong 阅读(222) 评论(0) 推荐(0) 编辑

十进制转二进制

摘要: 昨天无意间看到旁边的童鞋写十进制转二进制的程序,看电影的时候无聊,我也写一个练练手,转其它进制也是类似,就不多写了。仅供参考,做一个思路demo。 1 #include <stdio.h> 2 3 int binary[100]; 4 int index; 5 void tenToBinary(int decimal) 6 { 7 int divide = decimal/2; 8 if(divide>0) 9 tenToBinary(divide);10 binary[index++] = decimal%2;11 }12 13 int main(i... 阅读全文

posted @ 2013-03-17 12:14 xuangong 阅读(239) 评论(0) 推荐(0) 编辑

c语言字符串操作实现

摘要: 复试前,用字符串相关的操作来练练手。敲一遍总该用些用处。 1 #include <stdio.h> 2 #include <assert.h> 3 #include <malloc.h> 4 5 int strlen(const char *str) 6 { 7 assert(str!=NULL); 8 int len = 0; 9 while(*str++) 10 ++len; 11 return len; 12 } 13 14 char *strcpy(char *to, const char *from) 15 { 1... 阅读全文

posted @ 2013-03-17 12:04 xuangong 阅读(251) 评论(0) 推荐(0) 编辑

导航