C++
五条龙
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
剑指offer面试题6:重建二叉树
#include "iostream"#include #include "stack"using namespace std;struct BinaryTreeNode{ int data; BinaryTreeNode *left; BinaryTreeNode *right;};BinaryTreeNode* construct(int *preorder,int *ino原创 2016-07-09 22:31:41 · 267 阅读 · 0 评论 -
剑指offer面试题23:从上到下打印二叉树
#include "iostream"#include "iomanip"#include "stack"#include "queue"using namespace std;struct BinaryTreeNode{ int data; BinaryTreeNode *left; BinaryTreeNode *right;};void printFromTopToBot原创 2016-07-15 16:00:21 · 259 阅读 · 0 评论 -
剑指offer面试题24:二叉搜索树的后序遍历序列
#include "iostream"#include "iomanip"#include "stack"#include "queue"using namespace std;struct BinaryTreeNode{ int data; BinaryTreeNode *left; BinaryTreeNode *right;};bool verifySquenceOfBS原创 2016-07-15 16:28:04 · 267 阅读 · 0 评论 -
剑指offer面试题25:二叉树中和为某一值的路径
#include "iostream"#include "iomanip"#include "stack"#include "queue"#include "vector"using namespace std;struct BinaryTreeNode{ int data; BinaryTreeNode *left; BinaryTreeNode *right;};void原创 2016-07-15 17:12:10 · 365 阅读 · 0 评论 -
剑指offer面试题40:数组中只出现一次的数字
#include "iostream"using namespace std;unsigned int FindFirstBitIs1(int num){ int indexBit = 0; while (((num & 1) == 0) && (indexBit < 8 * sizeof(int))) { num = num >> 1; ++indexBit; } ret原创 2016-07-26 22:21:32 · 274 阅读 · 0 评论 -
剑指offer面试题43:n个骰子的点数
#include "iostream"using namespace std;int g_maxValue = 6;void PrintProbability(int number){ if (number < 1) return; int *pProbabilities[2]; pProbabilities[0] = new int[g_maxValue*number + 1]原创 2016-07-28 08:04:12 · 329 阅读 · 0 评论 -
剑指offer面试题3:二维数组中的查找
#include "iostream"#include using namespace std;bool find(int *matrix,int rows,int columns,int number ){ bool find = false; if (matrix != NULL&&rows > 0 && columns > 0) { int row = 0; int co原创 2016-07-08 14:36:15 · 281 阅读 · 0 评论 -
剑指offer面试题4:替换空格
#include "iostream"#include using namespace std;%length为字符数组p的总容量void replaceBlank(char *p,int length){ if (p == NULL || length <= 0) return; int blankNum = 0; int originalLength = 0; int i原创 2016-07-08 14:39:33 · 262 阅读 · 0 评论 -
剑指offer2.3.3链表:在链表末尾添加一个节点
#include "iostream"#include using namespace std;struct ListNode{ int data; ListNode *next;};void addToTail(ListNode **pHead,int value){ ListNode *pNew = new ListNode(); pNew->data = value; p原创 2016-07-08 15:19:06 · 1056 阅读 · 0 评论 -
剑指offer:2.3.3链表:删除第一个含有某值节点
#include "iostream"#include using namespace std;struct ListNode{ int data; ListNode *next;};void removeNode(ListNode **pHead,int value){ if (*pHead == NULL) return; ListNode *tobedelete=NU原创 2016-07-08 15:47:41 · 349 阅读 · 0 评论 -
剑指offer面试题5:从尾到头打印链表
#include "iostream"#include #include "stack"using namespace std;struct ListNode{ int data; ListNode *next;};void printdigui(ListNode *pHead){ if (pHead!=NULL) if (pHead->next != NULL) pri原创 2016-07-08 16:23:53 · 206 阅读 · 0 评论 -
剑指offer面试题27:二叉搜索树和双向链表
#include "iostream"using namespace std;struct BinaryTreeNode{ int data; BinaryTreeNode *left; BinaryTreeNode *right;};BinaryTreeNode *Convert(BinaryTreeNode *pRoot){ BinaryTreeNode *pLastNode原创 2016-07-19 16:19:59 · 296 阅读 · 0 评论 -
剑指offer面试题28:字符串的排列
#include "iostream"using namespace std;struct BinaryTreeNode{ int data; BinaryTreeNode *left; BinaryTreeNode *right;};void Permutation(char * pStr, char *pBegin){ if (*pBegin == '\0') cout原创 2016-07-19 17:25:47 · 345 阅读 · 0 评论 -
剑指offer面试题39:二叉树深度以及判断平衡二叉树
#include "iostream"using namespace std;struct BinaryTreeNode{ int data; BinaryTreeNode *left; BinaryTreeNode *right;};int TreeDeep(BinaryTreeNode *pRoot){ if (pRoot == NULL) return 0; int原创 2016-07-26 19:51:20 · 360 阅读 · 0 评论 -
剑指offer面试题38:数字在排序数组中出现的次数
#include "iostream"using namespace std;int GetFirstK(int *data, int length,int k, int start,int end){ if (start > end) return -1; int middleIndex = (start + end) / 2; int middleData = data[mid原创 2016-07-26 19:38:29 · 259 阅读 · 0 评论 -
剑指offer面试题18:树的子结构
#include "iostream"using namespace std;struct BinaryTreeNode{ int data; BinaryTreeNode *left; BinaryTreeNode *right;};bool doesTree1HasTree2(BinaryTreeNode *pRoot1, BinaryTreeNode *pRoot2){ i原创 2016-07-15 08:51:05 · 264 阅读 · 0 评论 -
剑指offer面试题7:用两个栈实现队列
#include "iostream"#include #include "stack"using namespace std;template class cQueue{public: void appendTail(const T ¬es); T deleteHead();private: stack stack1; stack stack2;};template原创 2016-07-10 14:57:20 · 254 阅读 · 0 评论 -
剑指offer2.4.1查找和排序:快速排序
#include "iostream"using namespace std;int randomInRange(int start,int end){return (rand() % (end-start+1) + start);}int partition(int data[],int length,int start,int end){if (data ==原创 2016-07-12 08:12:27 · 288 阅读 · 0 评论 -
剑指offer面试题8:旋转数组的最小数字
#include "iostream"#include #include "stack"using namespace std;int minInOrder(int* number, int index1, int index2);int min(int *number,int length){ if (number == NULL || length <= 0) throw ne原创 2016-07-11 22:06:37 · 251 阅读 · 0 评论 -
剑指offer面试题12:打印1到最大的n位数(1)
#include "iostream"using namespace std;bool Increment(char *number){ int length = strlen(number); int index = length-1; bool isOverFlow = false; for (int i = index; i >= 0;i--) { if (isOverF原创 2016-07-12 15:49:15 · 382 阅读 · 0 评论 -
剑指offer面试题12:打印1到最大的n位数(2)
#include "iostream"using namespace std;void printNumber(char *number){ int length = strlen(number); bool isBegin0 = true; for (int i = 0; i < length;i++) { if (isBegin0&&number[i] != '0')原创 2016-07-12 16:24:19 · 281 阅读 · 0 评论 -
剑指offer面试题14:调整数组顺序使奇数位于偶数前面
#include "iostream"using namespace std;void reOrder(int *data,int length){ if (data == NULL || length <= 0) return; int* start = data; int *end = data + length - 1; while (start<end) { whi原创 2016-07-12 20:06:20 · 228 阅读 · 0 评论 -
剑指offer面试题33:把数组排成最小的数
#include "iostream"using namespace std;const int gMaxLength=10;char* gCombine1 = new char[gMaxLength * 2 + 1];char* gCombine2 = new char[gMaxLength * 2 + 1];int compare(const void* strNum1, const原创 2016-07-25 08:47:07 · 260 阅读 · 0 评论 -
剑指offer面试题34:丑数
#include "iostream"using namespace std;int Min(int num1,int num2,int num3){ int min = num1 < num2 ? num1 : num2; min = min < num3 ? min : num3; return min;}int GetUglyNumber(int index){ if (原创 2016-07-25 14:45:56 · 357 阅读 · 0 评论 -
剑指offer面试题36:数组中的逆序对
#include "iostream"using namespace std;int InversePairsCore(int* data,int* copy,int start,int end){ if (start==end) { copy[start] = data[start]; return 0; } int length = (end - start) / 2;原创 2016-07-25 16:18:44 · 304 阅读 · 0 评论 -
剑指offer面试题17,18:反转链表+合并有序链表
#include "iostream"using namespace std;struct ListNode{ int data; ListNode *pnext;};ListNode* merge(ListNode *pHead1,ListNode *pHead2){ if (pHead1 == NULL) return pHead2; else if (pHead2 ==原创 2016-07-14 15:31:08 · 201 阅读 · 0 评论 -
剑指offer面试题20:顺时针打印矩阵(自己的算法,不是书上的)
#include "iostream"#include "iomanip"using namespace std;struct BinaryTreeNode{ int data; BinaryTreeNode *left; BinaryTreeNode *right;};void printMatrix(int number[][4],int rows,int columns){原创 2016-07-15 10:17:23 · 236 阅读 · 0 评论 -
剑指offer面试题19:二叉树的镜像
#include "iostream"using namespace std;struct BinaryTreeNode{ int data; BinaryTreeNode *left; BinaryTreeNode *right;};void mirrorRecursively(BinaryTreeNode *pNode){ if ((pNode == NULL) || (pN原创 2016-07-15 08:59:53 · 268 阅读 · 0 评论 -
面试题:给定一个字符串,问是否能通过添加一个字母将其变为回文串
题目描述给定一个字符串,问是否能通过添加一个字母将其变为回文串。输入描述:一行一个由小写字母构成的字符串,字符串长度小于等于10。 输出描述:输出答案(YES\NO). 输入例子:coco 输出例子:YES#include#include#include#include #include using原创 2016-08-22 08:33:46 · 4143 阅读 · 0 评论
分享