C++学习
C、C++
chaRon522
QQ:849663509
展开
-
unorderedmap根据键排序
#define _CRT_SECURE_NO_WARNINGS#include <iostream>#include <string>#include <math.h>#include <algorithm>#include <vector>#include <string.h>#include <sstream>#include <unordered_map>using namespace s原创 2021-02-02 17:38:00 · 2745 阅读 · 0 评论 -
C++day14---STL实现贪吃蛇
//wall.h#pragma once#ifndef _WALL_HEAD#define _WALL_HEAD#include <iostream>using namespace std;class Wall {public: enum { ROW = 26, COL = 26, }; //初始化墙壁 void initWall(); //展示墙壁 void draw(); //根据索引设置二维数组里的内容 void setWal...原创 2020-08-29 23:46:33 · 263 阅读 · 1 评论 -
C++day13---函数对象和常用算法
目录1. 函数对象2. 谓词使用3. 内建函数对象4. 适配器使用5. 常用算法5.1 遍历算法5.2 常用查找算法5.3 常用排序算法5.4 常用拷贝和替换算法5.4 常用算数生成算法6. 案例---演讲比赛1. 函数对象class myPrint {public: void operator()(int num) { cout << "num " << num << endl; }};void test() { myPrint print;//原创 2020-08-29 20:23:08 · 165 阅读 · 0 评论 -
C++day12---STL容器(下)
目录3 常用容器3.4 stack容器3.5 queue容器3.6 list容器3.7set容器3.8 map容器3.9 各容器使用时机3 常用容器3.4 stack容器3.5 queue容器3.6 list容器class Person {public: Person(string name,int age, int height) { this->name = name; this->age = age; this->height原创 2020-08-28 16:19:12 · 156 阅读 · 0 评论 -
C++day11---STL容器(上)
目录1. STL概念2. STL三大组件3. 常用容器3.1 string容器3.2 vector容器3.3deque容器1. STL概念2. STL三大组件2.1 容器2.2 算法2.3 迭代器#define _CRT_SECURE_NO_WARNINGS#include <iostream>#include <vector>#include <algorithm>#include <string>#include &原创 2020-08-27 22:23:27 · 125 阅读 · 0 评论 -
数据结构day10---队列和二叉树
目录1.队列概念2.链式队列实现3.树和二叉树的概念4.二叉树的递归遍历5.二叉树的高度和叶子节点数目6.二叉树的拷贝和释放7.二叉树的非递归遍历1.队列概念2.链式队列实现//linkQueue.h#pragma once#include <stdio.h>#include <stdlib.h>#include <string.h>#include <stddef.h>//可计算偏移量//为了在C++中能调用C写的函数#ifdef _原创 2020-08-26 16:31:02 · 332 阅读 · 0 评论 -
数据结构day09---栈
目录1.栈的概念2.栈的顺序存储3.栈的链式存储4.栈的应用---就近匹配1.栈的概念2.栈的顺序存储//seqStack.h#pragma once#include <string.h>#include <stdio.h>#include <stdlib.h>#include <stddef.h>//可计算偏移量#include <stdbool.h>#ifdef __cplusplusextern "C" {#e原创 2020-08-26 06:55:08 · 89 阅读 · 1 评论 -
数据结构day08---动态数组和单项链表
目录1.数据结构概念2.动态数组3.单向链表1.数据结构概念2.动态数组2.1 线性表基本概念2.2 线性表的顺序存储(动态数组)#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>#include <string.h>#include <stddef.h>//可计算偏移量//1.先定义所需要的数据信息结构struct dynamicArray原创 2020-08-26 04:45:03 · 150 阅读 · 0 评论 -
Cday07---预处理和动态库的封装
目录1.排序算法2.预处理指令3.库的基本概念4.动态库和静态库流程5.递归函数6.面向接口编程1.排序算法void selectSort(void* ptr, int ele_size, int ele_num, int(*compare)(void*, void*)) { char* temp = malloc(ele_size); for (int i = 0; i < ele_num; ++i) { int minOrmax = i; for (int j = i + 1;原创 2020-08-24 16:25:13 · 120 阅读 · 0 评论 -
Cday06---链表和函数指针
目录1.函数指针的定义2.函数指针做函数参数3.链表的定义4.静态链表5.动态链表的基本操作1.函数指针的定义void func() { printf("hello world!");}//func函数名其实是代表函数的入口地址//如何定义一个指向函数的指针int myfunc(int a, char b) { printf("int myfunc(int a, char b)\n"); return 0;}void test() { //1.定义函数类型,通过类型来定义函原创 2020-08-22 16:53:27 · 207 阅读 · 0 评论 -
Cday05---文件操作
目录1. 数组名2.结构体嵌套二级指针3.结构体偏移量4.内存字节对齐5.文件IO6.配置文件读写1. 数组名printArr1(int* arr, int len);printArr2(int(*arr)[3], int len);printArr3(char** arr, int len);void test() { //默认情况下数组名指向首元素地址,当取地址后指针指向整个数组 //如果只需要打印数组元素,是否取地址都可以。但如果要操控地址时, //指向整个数组的指针的步长不满足要求原创 2020-08-21 15:26:45 · 118 阅读 · 1 评论 -
Cday04---多维数组与结构体
1. 一维数组名void test() { int arr[] = { 1,2,3,4 };//数组名就是指向首元素的指针 //1.sizeof //2.对数组名取地址&arr //以上两种情况下,数组名不是指向首元素的指针,而是数组类型 //数组名是一个常量指针 printf("sizeof arr:%d\n", sizeof arr); printf("&arr address:%d\n", &arr); printf("&arr + 1 a原创 2020-08-20 16:35:18 · 258 阅读 · 0 评论 -
Cday03---calloc和realloc
1. calloc和reallocvoid test(){ int* p = calloc(10, sizeof(int)); for (int i = 0; i < 10; ++i) p[i] = i + 1; for (int i = 0; i < 10; ++i) printf("%d ", p[i]); if (p != NULL) { free(p); p = NULL; }}void test(){ int* p = malloc(原创 2020-08-12 14:05:16 · 166 阅读 · 0 评论 -
Cday02---指针问题(下)
1.指针的步长void test(){ //指针步长:指针变量+1,要向后跳多少字节 char* p1 = NULL; printf("%d\n", p1); printf("%d\n", p1 + 1); printf("----------------------------------\n"); int* p2 = NULL; printf("%d\n", p2); printf("%d\n", p2 + 1); //指针步长由指针类型决定}指针的类型不单单决定指针的步原创 2020-08-02 23:40:54 · 125 阅读 · 0 评论 -
Cday02---指针问题(上)
1.函数调用流程普通函数存在栈的开销问题,而宏函数则不存在。/*宏函数:不是一个真正的函数,在一定场景下比函数效率高,只是预处理器进行简单的文本替换*/#define MYADD(x,y) ((x)+(y))int main(){ int a = 10; int b = 20; //以空间换时间,对于频繁使用且短小的函数,使用宏函数代替 printf("a + b = %d\n", MYADD(a, b)); return 0;}2.函数的调用惯例3.函数原创 2020-08-01 18:51:23 · 120 阅读 · 0 评论 -
Cday01---内存分区
1原创 2020-07-26 01:17:19 · 109 阅读 · 0 评论