自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(18)
  • 资源 (1)
  • 收藏
  • 关注

转载 通过邻接矩阵找到两个节点的最近公共祖先结点

class Solution {public: //求根节点到目标节点(节点A或节点B)的路径path bool IsInTree(vector matrix,vector &path,int target,int index){ //先把当前节点放入路径中,再判断当前节点是否是目标节点 path.push_back(index);

2016-09-22 16:49:58 493

转载 最小K个数

#includeusing namespace std;int partition(int a[],int low,int high){ int prio = a[low]; while (low < high) { while (low = prio) high--; swap(a[high], a[low]); while (low < high && a[low] <

2016-09-18 15:51:47 160

原创 二叉树常见面试题汇总(改进版)

#include #include #include using namespace std;struct treeNode{ int data; treeNode *lson; treeNode *rson;};bool insert(treeNode *&root,int val)//插入值{ treeNode *p = new treeNode; p->data

2016-09-15 15:51:52 567

转载 二叉查找(最简单的递归)

#include#include#include using namespace std;#define N 5int binal(int a[], int start, int end, int val){ if (start <= end) { int index = (start + end) / 2; if (a[index] == val) return

2016-09-14 11:51:05 234

原创 C++ map的使用 (仿函数写法)

#include #include #include using namespace std;void main(){ map mym; //插入方法一 mym.insert(pair(1, "student1")); //插入方法二 //pair 为一个类型,比如int ,make_pair()函数返回类型为对应的pair类型 mym.insert(make_pair(

2016-09-14 10:39:51 1893 1

转载 在堆中创建二维数组

C++堆上申请二维数组假设要申请的是double型大小m*n数组有如下方法方法一:优点:申请的空间是连续的 缺点:较难理解1 double (*d)[n] = new double[m][n]方法二:优点:容易理解 缺点:申请的空间不能连续且需要多个指针才能管理double *d[m];for (int i=0; i) d[i] =

2016-09-14 10:25:07 3023 1

原创 判断整数k(k<1000)能被两个质数相加的组合(低效率 求高效率的方法)

#include #include #include #include #include using namespace std;bool check(int n){ for (int i = 2; i < n; i++) { if (n%i == 0) return false; } return true;}int count(int k){ int

2016-09-11 22:23:34 201

翻译 循环链表实现约瑟夫环(动态数组实现)

#include #include using namespace std;void main(){ int m, n; cin >> m >> n; int *num = new int[n]; for (int i = 0; i < n; i++) num[i] = 1; for (int i = 1, j = 0, k = 0; k < n; j = (++j) % n

2016-09-10 14:17:52 240

翻译 int转换为string

#include #include using namespace std;void main(){ int a = 20; char buf[10]; string str; sprintf(buf, "%d", a); str = buf; cout << str << endl; cout << str.length() << endl; system("pa

2016-09-10 11:04:25 146

翻译 大数加减乘除

#include #include using namespace std;string sub(string s1, string s2);string add(string s1, string s2){ if (s1.length() < s2.length()) { string temp = s1; s1 = s2; s2 = temp; } for (i

2016-09-07 18:03:32 182

翻译 string类

最后一个字符:mystr[mystr.size() - 1] = 'O';

2016-09-07 14:54:54 135

翻译 链表常见面试题

#include using namespace std;#include struct listNode { int data; listNode *next;};void insert(listNode **head, int value)//插入{ listNode *node = new listNode; node->next = NULL; node->data

2016-09-06 22:53:10 124

翻译 二进制的使用<bitset>

#include #include #include #include using namespace std;void main(){ int ch = -1; bitset mybit(ch); for (int i = 31; i >= 0; i--)  cout  string str1 = mybit.to_string();//转换为

2016-09-06 09:17:04 185

翻译 常见简单排序

1.1冒泡排序(原始版本)#include using namespace std;void bubbleSort(int a[],int n){ for (int i = 0; i <= n - 2; i++) { for (int j = 0; j <= n - 2 - i;j++) { if (a[j] < a[j + 1]) { swap(a

2016-09-03 15:13:16 148

翻译 字符串的全排列

#include using namespace std;void func(char *str,char *pbegin){ if (*pbegin == '\0') cout << str<<endl; for (char *p = pbegin; *p != '\0'; p++) { swap(*pbegin, *p); func(str, pbegin + 1);

2016-09-02 22:57:34 222 1

翻译 二叉树经典面试题汇总

二叉树经典面试题汇总#include using namespace std;#include #include class Tree;class treeNode{ friend class Tree;public: int data; treeNode *lson; treeNode *rson;};struct node1{ treeNode *btno

2016-09-01 20:54:50 206

翻译 重建二叉树

#include #include #include using namespace std;class Node {public: Node(char c) { data = c; lson = NULL; rson = NULL; } Node *lson; Node *rson; char data;};Node *rebuild(char *preOrder, ch

2016-09-01 20:53:25 119

翻译 翻转句子顺序

翻转句子顺序#include using namespace std;void reverse(char *a, char *b){while (a {char temp;temp = *a;*a = *b;*b = temp; a++;b--;}}void  fun(char *str){char

2016-09-01 20:39:29 216

华为电调天线解决方案(20120209)

华为电调天线解决方案(20120209)

2015-03-30

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除