- 博客(8)
- 资源 (5)
- 收藏
- 关注
原创 树的递归和非递归遍历
#include #include #include #include #include using namespace std; typedef struct BiNode { struct BiNode* lNode; struct BiNode* rNode; int data; }*BiTree; void createTree(BiTree &T) {
2015-02-25 09:53:58 503
原创 两两交换链表的结点
题目: 例如链表为1-->2-->3-->4,则交换后为:2-->1-->4-->3 代码: #include #include typedef struct ListNode { ListNode* next; int val; }; ListNode* swapNodeInPair(ListNode* head) { /*思
2015-02-17 10:34:24 875 2
原创 删除链表中重复的数
题目: 给定一个排序的链表,将其中重复的数全部删除。 比如:1-->1-->1-->2-->3,则返回2-->3 #include #include typedef struct ListNode { ListNode* next; int val; }; ListNode* rmDumplicateNums(ListNode* head)
2015-02-16 18:06:12 581
原创 格雷码与二进制之间的互换
#include #include /*格雷码转二进制*/ int grayToBin(int n) { int size = 0; int res[255]; int out = 0; int flag = 0; /*先缓存*/ while (n) { res[size++] = n%2;
2015-02-16 10:36:13 965
原创 设计包含min函数的栈
题目: 定义栈的数据结构,要求添加一个min函数,能够得到栈的最小元素。 要求函数min、push以及pop的时间复杂度都是O(1)。 代码: #include #include #define MAX_LEN_STACK 10 typedef struct { int stackList[MAX_LEN_STACK]; int to
2015-02-12 16:51:37 602
原创 重建二叉树
题目:如何根据二叉树的先序遍历和中序遍历结果还原二叉树?比如,先序遍历结果是{1,2,4,7,3,5,6,8},中序遍历结果是{4,7,2,1,5,3,8,6}; 参考:http://blog.csdn.net/chdjj/article/details/37961347 代码: #include #include #include struct
2015-02-11 20:58:58 503
原创 归并排序
#include #include /*将a[low--mid-1]和a[mid--high]合并,其中mid=(low+hihg)/2 基本上网上都是传入一个额外数组,这里直接作为局部数组,不作为参数加入 */ void mergeArray(int* a, int low, int high) { int tmp[255]; int i = low; int mid
2015-02-11 20:52:59 342
原创 数独题解
#include #include #define MAX_LEN 9 int sudoku[MAX_LEN][MAX_LEN] = { {5, 3, 0, 0, 7, 0, 0, 0, 0}, {6, 0, 0, 1, 9, 5, 0, 0, 0}, {0, 9, 8, 0, 0, 0, 0, 6, 0}, {8, 0, 0, 0, 6, 0, 0, 0, 3
2015-02-11 15:57:30 711
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人