摘要: 基本思想是:先对隔得比较远的元素进行比较,而不是像简单交换顺序算法中那样比较相邻的元素。这样可以快速地减少大量的无序情况,以后就可以少做些工作。各个被比较的元素之间的距离在逐步减少,一直减少到1,此时排序变成了相邻元素的互换。/*以递增顺序对v[0]、v[1]、......、v[n-1]进行排序*/void shellsort(int v[],int n){ int gap,i,j,temp; for(gap=n/2;gap>0;gap/=2) for(i=gap;i<n;i++) for(j=i-gap;j>=0&&v[j]>v[j+gap];... 阅读全文
posted @ 2013-06-04 17:10 欧小弟 阅读(142) 评论(0) 推荐(0) 编辑
摘要: for(i=0;i<n;i++) printf("%6d%c",a[i],(i%10==9||i==n-1)?'\n':' ');循环打印一个数组n个元素,每行打印10个元素,每一列之间用一个空格隔开,每行用一个换行符结束。i%9==0 ---- i从0开始算起。 阅读全文
posted @ 2013-06-04 15:28 欧小弟 阅读(142) 评论(0) 推荐(0) 编辑
摘要: #include <stdio.h>main(){ int c,i,nwhite,nother; int ndigit[10]; nwhite=nother=0; for(i=0;i<10;i++) ndigit[i]=0; while ((c=getchar())!=EOF) if(c>='0'&&c<='9') ++ndigit[c-'0']; else if(c==' '||c=='\n'||c=='\t') ++nwhite; else ... 阅读全文
posted @ 2013-06-03 16:19 欧小弟 阅读(425) 评论(0) 推荐(0) 编辑
摘要: #include <stdio.h>#define IN 1 /*在单词外*/#define OUT 0 /*在单词内*/main (){ int c,nl,nw,nc,state; state=OUT; nl=nw=nc=0; while((c=getchar()!=EOF) { ++nc; if (c=='\n') ++nl; if (c==' '||c=='\n'||c=='\t') state=OUT; else if (state==OUT) { ... 阅读全文
posted @ 2013-06-03 15:47 欧小弟 阅读(107) 评论(0) 推荐(0) 编辑
摘要: 算法思想:把用户的二进制数(1011)当作十进制进行处理,分别拆开成1 0 1 1四个数,然后用2*(2*((1*2)+0)+1)+1 = 11 得出十进制的值为11模块设计:除10取余函数:1011通过%10(除10取余),可得到1 1 0 1(逆序)计算十进制:循环处程序代码:#include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { while(1) { printf("enter num:"); int a; scanf("%d"... 阅读全文
posted @ 2013-06-02 17:00 欧小弟 阅读(234) 评论(0) 推荐(0) 编辑