C语言
文章平均质量分 61
lhbeggar
这个作者很懒,什么都没留下…
展开
-
C语言 二叉树按层打印、深度优先遍历、二叉树是否对称
#include#include#include//二叉树节点 typedef struct tree{ int data; struct tree *pLeft; struct tree *pRight;}Tree;//队列typedef struct queue{ struct node *pFront; struct node *pBehind; int size;原创 2015-05-08 15:17:46 · 1745 阅读 · 0 评论 -
C语言 求旋转数组的最小元素
#includeusing namespace std;int getMin(int *arr, int length){ if(arr == 0 || length <= 0){ throw new exception("Invalid parameters"); } int begin = 0; int end = length - 1; int middle; whil原创 2015-05-19 10:20:27 · 383 阅读 · 0 评论 -
C语言 数组中只出现一次的值
题目:一个整型数组里除了两个数字之外,其他的数字都出现了两次。请写程序找出这两个只出现一次的数字。要求时间复杂度是O(n),空间复杂度是O(1)。#includeusing namespace std;int findFirstBit1(int num){ int indexBit1 = 0; while((num & 1) == 0 && indexBit1 < 32){ nu原创 2015-05-19 10:56:10 · 627 阅读 · 0 评论 -
C语言 最大堆排序
#includeusing namespace std;int left(int i){ return 2*i;}int right(int i){ return 2*i+1;}int parent(int i){ return i/2;}void maxHeapify(int *arr, int length, int i){ if(arr == 0 || i < 0)原创 2015-05-21 21:17:05 · 857 阅读 · 1 评论 -
PHP静态成员变量和非静态成员变量
PHP静态成员变量和非静态成员变量突然在网上找到了一遍对PHP静态变量和非静态变量讲解比较深入的一遍文章,特转来分享下。转载地址:http://blog.chinaunix.net/uid-20722281-id-160034.html数据成员可以分静态变量、非静态变量两种. 静态成员:静态类中的成员加入static修饰符,即是静态成员.可以直接使用类名+静态成员名访问此静态成转载 2015-05-28 16:18:29 · 682 阅读 · 0 评论 -
C语言 开放寻址法HASH表存储简单实现
#include#include#include#include#include#include#define MAX_VALUE 5typedef struct hashNode{ char *key; char *value; int flag;}Hash;typedef struct table{ Hash *hashTable[MAX_VALUE]; int原创 2015-05-08 15:06:51 · 1027 阅读 · 0 评论 -
约瑟夫环的两种解法
题目:n个数字(0,1,…,n-1)形成一个圆圈,从数字0开始,每次从这个圆圈中删除第m个数字(第一个为当前数字本身,第二个为当前数字的下一个数字)。当一个数字删除后,从被删除数字的下一个继续删除第m个数字。求出在这个圆圈中剩下的最后一个数字。#include#include;using namespace std;int lastRemaining(int num, int m){原创 2015-05-20 10:22:03 · 832 阅读 · 0 评论 -
C语言 判断给定数组是否为二叉查找树后序遍历结果
题目:输入一个整数数组,判断该数组是不是某二元查找树的后序遍历的结果。如果是返回true,否则返回false。例如输入5、7、6、9、11、10、8,由于这一整数序列是如下树的后序遍历结果: 8 / \ 6 10 / \ / \ 5 7 9 11因此返回true#includeusing na原创 2015-05-20 13:59:33 · 611 阅读 · 0 评论 -
C语言 二叉查找树镜像
题目:输入一颗二元查找树,将该树转换为它的镜像,即在转换后的二元查找树中,左子树的结点都大于右子树的结点。用递归和循环两种方法完成树的镜像转换。例如输入: 8 / \ 6 10 /\ /\5 7 9 11输出: 8 / \ 10 6 /\ /\11 9 7原创 2015-05-20 11:11:16 · 556 阅读 · 0 评论 -
C语言 求二叉搜索树镜像的两种方法
typedef struct node{ int data; struct node *pLeft; struct node *pRight;}Node;//递归求解 void MirrorRecursive(Node *pRoot){ if(pRoot != NULL){ Node *temp = pRoot->pLeft; pRoot->pLeft = pRoot->p原创 2015-05-15 09:51:11 · 751 阅读 · 0 评论 -
C语言全排列
#include#include#include#include#define MAX_VALUE 30int next[] = { 1, 2, 3, 4 };void segnum(int sum, int * pData, int pDepth){ if(sum < 0){ return; } if(sum == 0){ for(int j=0; j<pDepth原创 2015-05-13 09:01:35 · 711 阅读 · 0 评论 -
C语言 拉链法HASH表存储
C语言实现Hashtable存储原创 2015-05-08 12:31:25 · 1191 阅读 · 0 评论 -
C语言 二分法查找之面试题
#include#include#include//二分法 递归 int binarysearch(int *arr, int begin, int end, int val){ if(begin end){ return -1; } int middle = (begin + end)/2; if(arr[middle] == val){ return 1; }el原创 2015-05-08 15:24:15 · 1039 阅读 · 0 评论 -
栈的push、pop序列[数据结构]
题目:输入两个整数序列。其中一个序列表示栈的push顺序,判断另一个序列有没有可能是对应的pop顺序。为了简单起见,我们假设push序列的任意两个整数都是不相等的。比如输入的push序列是1、2、3、4、5,那么4、5、3、2、1就有可能是一个pop系列。因为可以有如下的push和pop序列:push 1,push 2,push 3,push 4,pop,push 5,pop,pop,原创 2015-05-19 16:09:59 · 2354 阅读 · 0 评论