C/C++
i'm zaker
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
指针函数和函数指针简要说明
指针函数:返回指针的函数; 函数指针:只想函数的指针; 指针函数 int* fun1(int ,int); //指针函数的声明 函数指针 typedef int* (*fun_ptr)(int , int); //用typedef定义函数指针类型fun_ptr,这样较方便使用 fun_ptr fun=fun1; //定义了一个函数指针fun指向了指针函数fun1 fun(10,20);//通过函数指针fun调用了指针函数fun1 ...原创 2022-03-19 10:41:34 · 205 阅读 · 0 评论 -
C++容器与迭代器
STL常用容器的迭代器原创 2021-09-30 21:27:19 · 120 阅读 · 0 评论 -
C++ std::accumulate
C++中的accumulate是一个模板函数,要使用这个函数需要包含numeric这个头文件。 #include <iostream> #include <numeric> #include <vector> int main() { vector<double> vi = { 1.5,2,3 }; double res=std::accumulate(vi.begin(), vi.end(), 0.0); cout << res <&原创 2021-09-30 19:34:01 · 2382 阅读 · 0 评论 -
C++遍历
总结一下C++中的遍历方式 for循环 for_each循环 C++11中的for循环 #include <iostream> #include <thread> #include <algorithm> using namespace std; int f(int i) { cout << i << ' '; return 0; } int main() { int a[] = { 0,1,2 }; for (int i = 0;原创 2021-09-19 09:40:05 · 306 阅读 · 0 评论 -
数组初始化
直接给每个元素赋值 int array[4] = {1,2,3,4}; 部分赋值,后面的全部为0 int array[4] = {1,2}; 由赋值参数个数决定数组的个数 int array[] = {1,2}; 数组元素的值是随机分配的 int array[4] = {}; 实用方法:当初始化数组参数时,推荐使用 int array[4] = {0},这样可以把数组元素全都初始化为0; ...原创 2021-08-30 10:39:37 · 176 阅读 · 0 评论 -
C++实现冒泡排序和选择排序
C++实现冒泡排序和选择排序 #include <iostream> using namespace std; //冒泡排序 template<class T> void bubble_sort(T* a, T n) { for(int i=n;i>1;i--) for (int j = 0; j < i-1; j++) { if (a[j] > a[j + 1]) {原创 2021-05-06 22:44:46 · 204 阅读 · 0 评论 -
C++实现矩阵转置
#include <iostream> using namespace std; void zhuanzhi(int a[][3], int m, int n) { int temp = 0; for (int i = 0; i < m; i++) for (int j = i + 1; j < n; j++) { temp = a[i][j]; a[i][j] = a[j][i];原创 2021-05-13 21:06:23 · 1350 阅读 · 0 评论 -
C++实现插入排序
C++实现插入排序 思路: 1.从数组的第二个数据开始往前比较,即一开始用第二个数和他前面的一个比较,如果 符合条件(比前面的大或者小,自定义),则让他们交换位置。 2.然后再用第三个数和第二个比较,符合则交换,但是此处还得继续往前比较,比如有 5个数8,15,20,45, 17,17比45小,需要交换,但是17也比20小,也要交换,当不需 要和15交换以后,说明也不需要和15前面的数据比较了,肯定不需要交换,因为前 面的数据都是有序的。 3.重复步骤二,一直到数据全都排完。 //插入排序 void ins原创 2021-05-07 22:32:12 · 1326 阅读 · 0 评论 -
C++优先队列使用方法
1. 前言 最近在学习数据结构和算法,了解到优先级队列一般用堆这种数据结构来实现。实现方法不难,但是C++的STL库本身带有优先级队列priority_queue这种数据结构,只需要 #include <queue> 即可使用。其成员函数与普通的队列queue相似,都具有push、pop、top等成员函数。 2. 使用方法 #include <iostream> #include <queue> #include <vector> #include <原创 2021-06-29 21:51:17 · 673 阅读 · 2 评论 -
C++实现希尔排序、归并排序和快速排序
#include <iostream> using namespace std; //希尔排序 int* newarray = new int[12]; void shell_sort(int a[],int len) { int h = 1; while (h < len / 2) { h = 2 * h + 1; } while (h >= 1) { for (int i = 0; i < len; i++) { for (int j =原创 2021-06-25 17:04:47 · 249 阅读 · 0 评论 -
C++实现链表
头文件:定义节点和链表数据类型。实现构造、插入、删除等操作。 #pragma once #include <cstdlib> #include <iostream> using std::cout; using std::endl; struct linknode { int val; linknode* next; }; class linklist { public: linklist(); ~linklist(); bool insert(int); //尾插 值原创 2021-05-22 10:45:40 · 855 阅读 · 0 评论
分享