2014年9月14日

随机生成1024个数,存入一段内存,用指针实现获取1024个数的最大数地址,最小数地址

摘要: 题目:随机生成1024个数,存入一段内存,用指针实现获取1024个数的最大数地址,最小数地址,具体实现如下:#include#include#includeint FindMaxMinByIndex(int * pInput, int nLen, int ** ppMax, int ** ppMi... 阅读全文

posted @ 2014-09-14 23:59 三少爷的剑123 阅读(236) 评论(0) 推荐(0)

实现一个计算器

摘要: 题目:实现一个计算器,创建两个变量a,b,以及操作字符,实现输入“+”,执行加法,‘-’,执行减法,以此类推,有一个综合函数处理输入,有加减乘除求余5种运算,请用函数指针实现,以及函数指针作为参数来实现,具体实现如下:#include#includetypedef int(*FunPtr)(int... 阅读全文

posted @ 2014-09-14 23:48 三少爷的剑123 阅读(195) 评论(0) 推荐(0)

有两个指针pa,pb分别指向有两个数,a,b,请写一个函数交换两个指针的指向,也就是让pa指向b,让pb指向a

摘要: 题目:有两个指针pa,pb分别指向有两个数,a,b,请写一个函数交换两个指针的指向,也就是让pa指向b,让pb指向a,具体实现如下:#include #include int swap_ptr(int ** pA, int ** pB) { if (pA == NULL || pB ==... 阅读全文

posted @ 2014-09-14 23:43 三少爷的剑123 阅读(309) 评论(0) 推荐(0)

有两个数a,b,请写一个函数交换a,b

摘要: 题目:有两个数a,b,请写一个函数交换a,b,具体实现如下:#include#includeint swap(int * pA, int * pB){ if (pA == NULL || pB == NULL) { return 0; } int nTemp = *pA; *pA = *pB; ... 阅读全文

posted @ 2014-09-14 23:40 三少爷的剑123 阅读(144) 评论(0) 推荐(0)

开辟一个二维数组,有10*8个元素,用随机数填充,按照下面的方法用函数实现查找一个数是否存在

摘要: 题目:开辟一个二维数组,有10*8个元素,用随机数填充,按照下面的方法用函数实现查找一个数是否存在。具体实现如下:#include #include #include int find(int * pInput, int nLen, int nKey, int * pOut){ if (!pInp... 阅读全文

posted @ 2014-09-14 23:35 三少爷的剑123 阅读(197) 评论(0) 推荐(0)

生成一个一维数组,有10个元素,都用随机数填充,用指针轮询的办法实现函数查找一个数是否存在。

摘要: 题目:生成一个一维数组,有10个元素,都用随机数填充,用指针轮询的办法实现函数查找一个数是否存在,具体实现代码如下:#include #include #include int find(int * pInput, int nLen, int nKey, int * pOut){ if (!pI... 阅读全文

posted @ 2014-09-14 23:28 三少爷的剑123 阅读(365) 评论(0) 推荐(0)

随机生成3个数,创建3个指针指向这3个数,不改变这3个数,从大到小显示。

摘要: 题目:随机生成3个数,创建3个指针指向这3个数,不改变这3个数,从大到小显示,具体实现如下:#include#include#includevoid main(){ int a = 0; int b = 0; int c = 0; srand(time(NULL)); a = 3; //rand(... 阅读全文

posted @ 2014-09-14 23:24 三少爷的剑123 阅读(229) 评论(0) 推荐(0)

在一个字符串中找到第一个只出现一次的字符

摘要: 题目:在一个字符串中找到第一个只出现一次的字符,如输入abaccdeff,则输出b;具体实现如下:#include #include using namespace std;void FindChar(const string &strBuf){ int nArr[256]; //ASCI... 阅读全文

posted @ 2014-09-14 22:52 三少爷的剑123 阅读(208) 评论(0) 推荐(0)

输入一颗二元树,从上向下按层打印树的每个节点,同一层中,按照从左到右的顺序打印。

摘要: 输入一颗二元树,从上往下按层打印树的每个结点,同一层中按照从左往右的顺序打印,具体实现如下:#include using namespace std;typedef struct BSTNode{ int nValue; struct BSTNode *pLChild; struct BSTNod... 阅读全文

posted @ 2014-09-14 22:42 三少爷的剑123 阅读(143) 评论(0) 推荐(0)

输入一个单向链表,输出该链表中倒数第K个结点

摘要: 输入一个单向链表,输出该链表中倒数第K个结点,具体实现如下:#include using namespace std;struct LinkNode{public: LinkNode(int value = 0) : nValue(value){ pNext = NULL; } ~Link... 阅读全文

posted @ 2014-09-14 22:34 三少爷的剑123 阅读(281) 评论(0) 推荐(0)

查找最小的K个元素,使用最大堆。

摘要: 查找最小的K个元素,使用最大堆,具体代码如下:#define _CRT_SECURE_NO_WARNINGS #include using namespace std; void swap(int *a, int *b) { int temp; temp = *a; *... 阅读全文

posted @ 2014-09-14 22:25 三少爷的剑123 阅读(236) 评论(0) 推荐(0)

判断整数序列是不是二元查找树的后序遍历结果

摘要: 题目:输入一个整数数组,判断该数组是不是二元查找树的后序遍历结果,如果是,返回true,否则返回假,具体实现如下:#include using namespace std;//搜索树后序遍历数组最后一个是根,从数组头到第一个比根大的节点是左孩子,后面右孩子必须全大于根,递推static bool ... 阅读全文

posted @ 2014-09-14 22:12 三少爷的剑123 阅读(136) 评论(0) 推荐(0)

链队

摘要: 今天,我们一起用C++写一个链对,具体如下所示。LinkQueue.h具体内容如下:#include "QueueNode.h"template class LinkQueue{public: LinkQueue() :m_prear(NULL), m_pfront(NULL){} ~Li... 阅读全文

posted @ 2014-09-14 18:34 三少爷的剑123 阅读(141) 评论(0) 推荐(0)

链栈

摘要: 今天,我们一起用C++写链栈,具体如下。LinkStack.h具体内容:#include "StackNode.h"template class LinkStack{public: LinkStack() :m_ptop(NULL){} ~LinkStack(){ MakeEmpty()... 阅读全文

posted @ 2014-09-14 18:24 三少爷的剑123 阅读(114) 评论(0) 推荐(0)

基数排序

摘要: 今天,我们一起用C++实现基数排序,具体代码如下:Data.h具体内容如下:template class Element{public: Type GetKey(){ return key; } void SetKey(Type item){ key = item; }public: ... 阅读全文

posted @ 2014-09-14 18:11 三少爷的剑123 阅读(122) 评论(0) 推荐(0)

合并排序

摘要: 今天,我们的目标就是一起用C++实现合并排序,具体代码如下。Data.h具体内容:template class Element{public: Type GetKey(){ return key; } void SetKey(Type item){ key = item; }publi... 阅读全文

posted @ 2014-09-14 18:01 三少爷的剑123 阅读(91) 评论(0) 推荐(0)

堆排序

摘要: 今天,我们一起用C++实现堆排序,目的是熟练C++的语法,具体代码如下。Data.h具体内容如下:template class Element{public: Type GetKey(){ return key; } void SetKey(Type item){ key = item... 阅读全文

posted @ 2014-09-14 17:46 三少爷的剑123 阅读(96) 评论(0) 推荐(0)

选择排序

摘要: 今天,我们一起用C++实现一个选择排序,帮助大家熟练C++的语法,具体内容如下:Data.h的内容:template class Element{public: Type GetKey(){ return key; } void SetKey(Type item){ key = it... 阅读全文

posted @ 2014-09-14 17:39 三少爷的剑123 阅读(126) 评论(0) 推荐(0)

冒泡排序

摘要: 今天,我们一起用C++写一个冒泡排序,目的就是通过不断地实践来熟练C++,具体代码如下:Data.h具体内容:template class Element{public: Type GetKey(){ return key; } void SetKey(Type item){ key ... 阅读全文

posted @ 2014-09-14 17:22 三少爷的剑123 阅读(162) 评论(0) 推荐(0)

希尔排序

摘要: 今天,我们一起用C++实现希尔排序,具体的代码如下:Data.h内容如下:template class Element{public: Type GetKey(){ return key; } void SetKey(Type item){ key = item; }public: E... 阅读全文

posted @ 2014-09-14 17:12 三少爷的剑123 阅读(132) 评论(0) 推荐(0)

导航