上一页 1 2 3 4 5 6 7 8 ··· 11 下一页
摘要: 1 #include "stdafx.h" 2 #include 3 #include 4 #include 5 using namespace std; 6 7 void Swap(int *lhs,int *rhs) 8 { 9 int temp = *lhs;10 *lhs = *rhs;11 *rhs = temp;12 }13 14 int Partition(int* Array,int begin,int end)15 {16 int ran = begin+ rand() % (end-begin+1);//生成一个从begin到end... 阅读全文
posted @ 2014-02-20 14:18 CrazyCode. 阅读(134) 评论(0) 推荐(0) 编辑
摘要: #include "stdafx.h"#include #include #include using namespace std;/* 重建二叉树题目:输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树. 假设输入的前序遍历和中序遍历的结果中都不含重复的数字.例如 输入前序遍历序列{1,2,4,7,3,5,6,8}和中序遍历序列{4,7,2,1,5,3,8,6}, 则重建出图所示的二叉树并输出它的头结点。二叉树结点的定义如下:*/struct BinaryTreeNode{ int m_nValue; BinaryTreeNode* m_p... 阅读全文
posted @ 2014-02-20 01:18 CrazyCode. 阅读(1494) 评论(0) 推荐(0) 编辑
摘要: 1 #include "stdafx.h" 2 #include 3 #include 4 #include 5 using namespace std; 6 7 /*从尾到头打印链表*/ 8 /* 9 题目:输入一个链表的头结点,从尾到头反过来打印出每个结点的值。10 */11 struct ListNode12 {13 int m_nValue;14 ListNode* m_pNext;15 };16 17 //根据后进先出的思想,考虑用栈的方法18 void PrintListReversingly_Iteratively(ListNode* pHead)19 ... 阅读全文
posted @ 2014-02-19 23:34 CrazyCode. 阅读(258) 评论(0) 推荐(0) 编辑
摘要: 1 #include "stdafx.h" 2 #include 3 #include 4 using namespace std; 5 6 struct ListNode 7 { 8 int m_nValue; 9 ListNode* m_pnext;10 };11 12 void InsertNodeTail(ListNode** L,int num)13 {14 ListNode* node = new ListNode();15 node->m_nValue = num;16 node->m_pnext = NULL;17 if(... 阅读全文
posted @ 2014-02-19 23:23 CrazyCode. 阅读(422) 评论(0) 推荐(0) 编辑
摘要: 1 #include "stdafx.h" 2 #include 3 #include 4 using namespace std; 5 6 /*替换空格*/ 7 /* 8 题目:请实现一个函数,把字符串中的每个空格替换成"%20".例如输入"We are happy",则输出"We%20are%20happy". 9 */10 int ReplaceBlank(char string[],int length)11 {12 int i = 0;13 int blankNum=0;14 int strLength= 阅读全文
posted @ 2014-02-19 20:45 CrazyCode. 阅读(575) 评论(0) 推荐(0) 编辑
摘要: 1 #include "stdafx.h" 2 #include 3 #include 4 using namespace std; 5 6 /*二维数组中的查找*/ 7 /* 8 题目: 9 在一个二维数组中,每一行都按照从左到右递增的顺序排序,10 每一列都按照从上到下递增的顺序排序.请完成一个函数,11 输入这样的一个二维数组和一个整数,12 判断数组中是否含有该整数.13 */14 bool FindNumber(int *matrix,int columns,int rows,int key)15 {16 bool found = false;17 if(ma.. 阅读全文
posted @ 2014-02-19 13:45 CrazyCode. 阅读(170) 评论(0) 推荐(0) 编辑
摘要: 1 #include "stdafx.h" 2 #include 3 #include 4 using namespace std; 5 6 /*排序用到的结构*/ 7 const int maxSize = 10; 8 typedef struct 9 {10 int r[maxSize+1];11 int length;12 }SqList;13 14 /*数组元素交换*/15 void swap(SqList *L,int i ,int j)16 {17 int temp = L->r[i];18 L->r[i] = L->r[j];19 ... 阅读全文
posted @ 2014-02-16 17:30 CrazyCode. 阅读(150) 评论(0) 推荐(0) 编辑
摘要: 1 #include "stdafx.h" 2 #include 3 #include 4 using namespace std; 5 6 /*排序用到的结构*/ 7 const int maxSize = 10; 8 typedef struct 9 {10 int r[maxSize+1];11 int length;12 }SqList;13 14 /*数组元素交换*/15 void swap(SqList *L,int i ,int j)16 {17 int temp = L->r[i];18 L->r[i] = L->r[j];19 ... 阅读全文
posted @ 2014-02-16 16:52 CrazyCode. 阅读(202) 评论(0) 推荐(0) 编辑
摘要: 1 #include "stdafx.h" 2 #include 3 #include 4 using namespace std; 5 6 /*散列表查找实现 7 散列表如果没有冲突,查找效率就非常高的.时间复杂度是O(1);但是实际应用中,冲突是不可避免的. 8 那么散列表的平均查找长度取决于 9 1.散列函数是否均匀.10 2.处理冲突的方法.11 3.散列表的装填因子.a = 填入表中的记录个数 / 散列表的长度.当a越大,产生冲突的可能性就越大.12 用空间来换取时间13 */14 const int success = 1;15 const int unSucc 阅读全文
posted @ 2014-02-16 15:56 CrazyCode. 阅读(356) 评论(0) 推荐(0) 编辑
摘要: 1 #include "stdafx.h" 2 #include 3 #include 4 #include 5 using namespace std; 6 7 8 /* 9 二叉排序树:又称为二叉查找树,它或者是一棵空树,或者具有如下性质:10 1.若他的左子树不空,则左子树上所有结点的值均小于它的根结点的值.11 2.若它的右子树不空,则右子树上所有结点的值均大于它的根结点的值.12 3.它的左右子树也分别为二叉排序树.13 如中序遍历,则可获得有序序列.14 */15 16 typedef struct BiTNode17 {18 int data;19 st... 阅读全文
posted @ 2014-02-16 15:19 CrazyCode. 阅读(215) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 8 ··· 11 下一页