自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(95)
  • 收藏
  • 关注

原创 char s[]和char *s的区别

char *s1="hello";//声明一个指针指向常量"hello"char s2[]="hello";//在栈中开辟一个数组字符"hello";/** s2[]="hello" 相当于* char s2[6];* s2[0]='h';* s2[1]='e';* s2[2]='l';* s2[3]='l';* s2[4]='0';* s2[5]='\0';**/...

2020-02-19 20:49:35 274

原创 递归汉诺塔

#include <iostream>#include <string>using namespace std;void process(int n,string from,string to,string help){ if(n==1){ cout<<"Move 1 "<<"from"<<from&lt...

2020-02-19 19:07:34 173

原创 07/15仿函数

函数绑定:#include <iostream>#include <functional>//处理函数using namespace std;using namespace std::placeholders;struct MyStruct{ void add(int a) { cout << a << endl; ...

2020-02-19 16:29:14 132

原创 引用包装器

函数副本机制:#include <iostream>template<class T>void com(T arg){ arg++;}void main(){ int count = 10; com(count); std::cout << count << std::endl; system("pause");}...

2020-02-19 15:13:00 137

原创 自动数据类型

自动数据类型,根据实际推导出类型函数类型可以使用auto,但是参数不允许使用autotemplate<class T1,class T2>//根据类型获取类型#include <stdlib.h>#include <iostream>//获取变量的数据类型 变量->decltype/*auto get(int num,double...

2020-02-19 14:50:29 110

原创 函数模板以及自动类型

传统的函数定义,但若数据类型丰富,需要重载过多的函数。#include <stdlib.h>#include <iostream>//数组作为参数时,会退化为指针int getmax(int *p,int n){ int max(0); max = p[0]; for (int i = 0; i < 10; i++) { if (max&...

2020-02-19 14:36:04 163

原创 inline函数

inline函数:内联函数C语言使用define函数。这样的话,速度较慢。#include <stdlib.h>#include <iostream>//替换#define GETX3(N) N*N*N//1+2*1+2*1+2//函数 int getX3(int x){ return x*x*x;}//define可以实现泛...

2020-02-19 12:54:31 106

原创 二叉树的后继节点

后继节点:就是一个节点在中序遍历中的下一个节点。在中序遍历中,如果该节点有右子树,该节点的后继节点,就是再二叉树中,该节点的右子树中,最左的节点。当x节点没有右子树,就去查找x是哪个节点的左子树。...

2020-02-15 13:28:48 1383

原创 C与CPP的别名

C的别名:#include <iostream>int add(int a, int b){ return a + b;}typedef int(*ADD)(int a, int b);void main(){ ADD p = add; std::cout << p(1, 2) << std::endl; std::cin.ge...

2020-02-14 17:06:54 163

原创 去掉-转义字符(启动exe文件)

#include <iostream>#include <string>#include <stdlib.h>void main(){ std::string path = R"("D:\QQ\Bin\QQScLauncher.exe")"; //R"()"去掉括号里面的转义字符 system(path.c_str()); system("p...

2020-02-14 12:35:01 82

原创 函数绑定

#include <iostream>#include <functional>//处理函数using namespace std;using namespace std::placeholders;struct MyStruct{ void add(int a) { cout << a << endl; } void a...

2020-02-14 12:12:29 70

原创 二叉树的非递归遍历

中序遍历:当前节点不为空,就把当前节点压栈。然后走当前节点的左节点。当前节点为空,把栈的top()拿出来,并将top()赋值为当前节点。然后,走当前节点的右节点。...

2020-02-13 20:59:08 78

原创 二叉树的递归遍历

#include <stdio.h>#include <stdlib.h>#include <iostream>#include <stack>using namespace std;typedef struct node { int data; struct node* left; struct node* r...

2020-02-13 16:52:01 72

原创 判断一个单链表是否有环以及判断两个单链表是否相交

判断一个单链表是否有环:方法1:使用hash_map,当map中出现重复的值时,该值即为环的第一个节点。方法2:两个指针,快指针一次走两步,慢指针一次走一步,当快慢指针相遇时,将快指针放于head位置,快指针由一次走两步变成一次走一步,快指针和慢指针一定会在第一个入环节点处相遇。。判断两个链表是否相交:方法1:使用map,将链表1全部加入map中,然后依次查找...

2020-02-13 12:13:23 167

转载 c++ hash_map用法总结

c++ STL库里有自定义的hash_map 方法,但是使用起来并不是那么方便hash_map主要的方法有find(),insert()我结合官方API说明一下他们的用法一、需要特别注意的地方,1.头文件的引用2.如何插入一个<key,value>键值对(参考一下代码)3.find()的返回值4.如何获取某一个key值相应的value值hm1_R...

2020-02-13 10:49:22 2462

原创 在一个已排序的二维数组中,找到指定数字的位置

在一个已排序的二维数组中,找到指定数字的位置二维数组排序规则:列从上到小依次增加,行从左到右以此增加/*给定一个有N*M的整型矩阵matrix和一个整数K, matrix的每一行和每一 列都是排好序的。实现一个函数,判断K 是否在matrix中。*/#include <iostream>using namespace std;int main(){ in...

2020-02-12 16:29:53 885

转载 c++STL中优先队列的使用

优先队列即为,堆说到队列,我们首先想到就是先进先出,后进后出;那么何为优先队列呢,在优先队列中,元素被赋予优先级,当访问元素时,具有最高级优先级的元素先被访问。即优先队列具有最高级先出的行为特征。优先队列在头文件#include <queue>中;其声明格式为:priority_queue <int> ans;//声明一个名为ans的整形的优先队列基本...

2020-02-08 16:59:17 133

原创 大数乘法

#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include<stdlib.h>#include<string.h>//C语言声明变量需要加上stuct//C语言结构内部不可以有函数//C语言结构体没有公有,私有,继承struct MyStruct{ int num1; int ...

2020-02-08 16:44:00 76

原创 简单的比较器

#include <iostream>#include <algorithm>using namespace std;int a[1001];bool cmp(int a,int b){ return a>b;}int main(){ int n; cin>>n; for(int i=0;i<n;...

2020-02-08 16:26:03 189

原创 荷兰国旗

#include <iostream>using namespace std;int a[100];void swap_t(int a[],int l,int i){ int t=a[l]; a[l]=a[i]; a[i]=t;}void p_sort(int *a,int n,int num){ int l=-1,m=n; ...

2020-02-08 16:24:08 158

原创 普通快排

参考链接 :http://blog.sina.com.cn/s/blog_5c5bc9070100y4zv.html#include <iostream>#include <stdlib.h>#include <time.h>#include <bits/stdc++.h>using namespace std;int a[10000...

2020-02-08 16:23:41 182

原创 冒泡排序

#include <iostream>using namespace std;//exchange the 2 items a and bvoid swap(int &a, int &b){ a = a + b; b = a - b; a = a - b;}//ergodic the buf and print itvoid ...

2020-02-08 16:09:43 89

原创 vector的二维数组

#include <iostream>#include <vector>#include <algorithm>void main1(){ std::vector<int> myvector; myvector.push_back(1); myvector.push_back(2); myvector.push_back(3);//...

2020-02-08 12:00:33 452

原创 C++11的新性能:lambda

#include <iostream>#include <vector>#include <algorithm>void main(){ std::vector<int> myvector; myvector.push_back(1); myvector.push_back(2); myvector.push_back(3);//统...

2020-02-08 11:23:03 128

原创 C++高级数组

#include <iostream>#include <array>#include <vector>/C++的标准库#include <string>//C++字符串using std::vector;//动态数组,堆上using std::array;//静态数组,栈上using std::string;//使用C++风格的数...

2020-02-08 10:27:38 237

原创 Cpp新类型数组

#include <iostream>#include <array>#include <string>#include <stdlib.h>void main1(){ double db[4] = { 1.1,2.2,3.3,4.4 }; //std::array数据类型,double元素类型,4为个数 std::array...

2020-02-07 21:47:14 175

原创 C++的数据类型转换

#include <iostream>#include <stdio.h>void main1(){ double db = 10.9; float fl = db; std::cin.get();}void main2(){ void *p = new int[10]; int *pint = (int*)p;//C语言风格 }void...

2020-02-07 19:52:08 115

原创 高级函数模板

Struct#include<iostream>struct info{ char name[40]; double db; int data;};template <typename T>void swap(T &a,T &b){ std::cout << "通用函数模板" << std::e...

2020-02-07 17:46:03 74

原创 函数模板

#include <stdlib.h>#include <iostream>template<typename T> T MAX(T*p, const int n){ T maxdata(p[0]); for (int i = 1; i < n; i++) { if (maxdata < p[i]) { maxdata...

2020-02-06 21:20:11 72

原创 bool变量

#include <iostream>#include <stdlib.h>void main(){ bool b1 = 1 && 1 || 2 || -1 && 0; std::cout << b1 <<std::endl; system("pause");}&&的优先级高于|...

2020-02-05 19:25:20 131

原创 auto

#include <iostream>void main(){ double db = 10.9; double *pdb = &db; auto num = pdb;//通用的传入接口 std::cout << typeid(db).name() << std::endl; std::cout << typeid(num)...

2020-02-05 17:15:29 157

原创 QT_T04-COOD

//应用程序抽象类#include<QApplication>//按钮#include <QPushButton>//窗口类#include <QWidget>int main(int argc,char *argv[]){ QApplication app {argc,argv}; //构造一个窗口 QWidget ...

2020-02-05 15:07:34 122

原创 QT_T02_LineEdit

//应用程序抽象类#include<QApplication>//按钮#include <QPushButton>//窗口类#include <QWidget>#include <QLineEdit>#include <QCompleter>int main(int argc,char *argv[]){ QA...

2020-02-05 14:55:19 100

原创 QT_T01_helloworld

//应用程序抽象类#include<QApplication>//按钮#include <QPushButton>//窗口类#include <QWidget>int main(int argc,char *argv[]){ QApplication app {argc,argv}; //构造一个窗口 QWidget ...

2020-02-05 14:54:24 104

原创 C、CPP的const

C和C++的const的区别本质上,C++的const为一个常量,所以可以初始化数组。而C的const为一个伪常量不可以初始化数组。C:#include <stdio.h>void main(){ const int num = 5;//C语言的const属于伪常量 int a[num];//所以此处报错}CPP:#include <iostre...

2020-02-04 20:10:19 140

原创 左值和右值

#include <iostream>void main(){ int num1(5); int num2(10); int *pnum(&num1); std::cout <<"pnum的地址:"<< pnum << std::endl; std::cout <<"num1的地址" <<&nu...

2020-02-04 16:14:18 97

原创 左值引用

#include <iostream>void main1(){ int a = 5; int & ra (a);//引用初始化,引用必须初始化 ra = 3; std::cout << a << std::endl; system("pause");}void change(int a){ a = 19; std::cou...

2020-02-04 15:21:52 78

原创 auto

#include <iostream>void main1(){ auto num = 10.9; auto numA = 10/2.0; std::cout << num << " " << numA << std::endl; system("pause");}void main(){ double num[...

2020-02-04 14:49:56 53

原创 C语言函数地址的打印

#include<iostream>#include<stdio.h>//参数的个数,参数的类型不同,顺序不同,返回值无关void go(int a){ std::cout << a;}void go(double a){ std::cout << a;}void go(double a, int b){ std::...

2020-02-03 16:41:11 5359

原创 函数重载在汇编里面

这也就是为什么C++可以实现函数重载,而C语言不可以实现函数重载

2020-02-03 16:06:07 118

空空如也

空空如也

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

TA关注的人

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