coding----1wcods----坚持第2天----239行
2013-12-22 00:57
330 查看
#include <stdio.h> int main(void) { int sum = 0, i = 0; char input[5]; /* 测试段错误 */ // int man = 0; // scanf("%d", man); while (1) { scanf("%s", input); for (i = 0; input[i] != '\0' && i != 4; i++) { sum = sum*10 + input[i] - '0'; } printf("input=%d\n", sum); sum = 0; } return 0; } /************************************************************************* > File Name: insertion_sort.c > Author: Michael.Zhang > Mail: muge0913@sina.com > Created Time: Sat 21 Dec 2013 06:34:14 PM CST ************************************************************************/ #include "insertion_sort.h" void array_info(int *array, int len) { for (int i = 0; i < len; i++) { printf("array[%d]=%-4d", i, array[i]); } printf("\n"); } void insertion_sort(int * array,int len) { int i = 0, key = 0; for (int j = 1; j < len; j++) { // array_info(a, len); key = array[j]; i = j - 1; while (i >= 0 && array[i] > key) { array[i + 1] = array[i]; i--; } array[i + 1] = key; } // array_info(a, len); } /************************************************************************* > File Name: insertion_sort.h > Author: Michael.Zhang > Mail: muge0913@sina.com > Created Time: Sat 21 Dec 2013 06:38:19 PM CST ************************************************************************/ /* * 插入排列的时间复杂度为O(n^2) */ #ifndef __INSERTION_SORT_H__ #define __INSERTION_SORT_H__ #include <stdio.h> extern void array_info(int *array, int len); extern void insertion_sort(int * array,int len); #endif #include <stdio.h> #include "insertion_sort.h" #define LEN 5 int main() { int a[LEN] = { 10, 5, 2, 4, 7 }; insertion_sort(a,LEN); array_info(a,LEN); return 0; } #include <stdio.h> #include <stdlib.h> #include <stddef.h> typedef char elem; typedef struct binary_tree_node { elem data; struct binary_tree_node *lchild, *rchild; } binary_tree_node, *binary_tree; void create_binary_tree (binary_tree *binary_tree_tst) { printf("Create\n"); char ch = getchar(); while('\n' !=getchar()); if ('#' == ch) *binary_tree_tst = NULL; else { *binary_tree_tst = (binary_tree_node *)malloc(sizeof(binary_tree_node)); (*binary_tree_tst)->data = ch; create_binary_tree (&(*binary_tree_tst)->lchild); create_binary_tree (&(*binary_tree_tst)->rchild); } } void pre_order_traverse(binary_tree binary_tree_tst) { if (binary_tree_tst == NULL) return; printf ("%c\n", binary_tree_tst->data); pre_order_traverse (binary_tree_tst->lchild); pre_order_traverse (binary_tree_tst->rchild); } int main () { binary_tree binary_tree_tst; create_binary_tree (&binary_tree_tst); pre_order_traverse (binary_tree_tst); return 0; }
相关文章推荐
- 设计模式-策略模式
- Android如何防止apk程序被反编译
- POJ3461 Oulipo KMP算法
- 一些算法的MapReduce实现——矩阵分块乘法计算(2)
- 彻底理解javascript的回调函数(推荐)
- 在响应链中使用视图控制器Using View Controllers in the Responder Chain[苹果官方文档的翻译]
- java反射详解
- Java使用PropertyDescriptor获取实体类中私有属性的值,并给私有属性赋值
- 使用python的logging模块
- UESTC-第五届ACM趣味程序设计竞赛第四场(正式赛)--不完全解题报告
- 使用python的logging模块
- 使用python的logging模块
- 使用python的logging模块
- 读JS高级API笔记_(DOM&&DOM2&&DOM3)哎呀——园龄才9个月啊
- Ant 安装与配置
- Yii tips 2
- HDOJ 1039 Easier Done Than Said?
- 用STL实现堆容器
- svn 改英文
- XDU Problem 1255 - 数列游戏