摘要: 二分查找 简易版 参考 K&R C #include <stdio.h> //binsearch函数: 在v[0..n-1]中查找x,其中v[i]<=v[i+1] //若找到返回下标(0-base),若找不到返回-1; int binsearch(int v[], int x, int low,in 阅读全文
posted @ 2016-02-25 23:04 hopskin1 阅读(167) 评论(0) 推荐(0) 编辑
摘要: 将数字n转换为字符串并保存到s中 参考 C程序设计语言 #include <stdio.h> #include <string.h> //reverse函数: 倒置字符串s中各字符的位置 void reverse(char s[]){ int c,i,j; for(i=0,j=strlen(s)-1 阅读全文
posted @ 2016-02-25 20:55 hopskin1 阅读(410) 评论(0) 推荐(0) 编辑
摘要: 倒置字符串s中各字符的位置 其中reverse函数可以写成更紧凑的形式 void reverse(char s[]){ int c,i,j; for(i=0,j=strlen(s)-1;i<j;i++,j--){ c=s[i], s[i]=s[j], s[j]=c; } } 程序 #include 阅读全文
posted @ 2016-02-25 20:35 hopskin1 阅读(301) 评论(0) 推荐(0) 编辑
摘要: 希尔排序 不知道怎么证明希尔排序的正确性 #include<stdio.h> void view(int Av[]); void shellsort(int v[], int n){ int gap, i, j, temp; for(gap=n/2;gap>0;gap/=2){ for(i=gap; 阅读全文
posted @ 2016-02-25 20:25 hopskin1 阅读(134) 评论(0) 推荐(0) 编辑
摘要: 参考《C程序设计语言》 注意输出中光标的位置 对于getline, 由于函数的默认返回值类型为int, 因此这里的int可以省略。 #include<stdio.h> #define MAXLINE 4 //允许的输入行的最大长度 //getline函数: 将一行读入到s中并返回其长度 int ge 阅读全文
posted @ 2016-02-25 11:42 hopskin1 阅读(483) 评论(0) 推荐(0) 编辑
摘要: 统计输入的行数,单词数和字符数 #include<stdio.h> #define IN 1 /*在单词内*/ #define OUT 0 /*在单词外*/ //统计输入的行数,单词数和字符数 int main(){ int c, nl, nw, nc, state; nw=nl=nc=0; sta 阅读全文
posted @ 2016-02-25 10:52 hopskin1 阅读(1279) 评论(0) 推荐(0) 编辑
摘要: 回退符\b #include <stdio.h> int main(){ printf("hello\b"); getchar(); getchar(); return 0; } 实验结果 阅读全文
posted @ 2016-02-25 09:45 hopskin1 阅读(451) 评论(0) 推荐(0) 编辑