- 博客(5)
- 收藏
- 关注
原创 C++ new数组 && C++求数组最大值和最小值(最简单方式)
C++ new数组:#include<iostream>using namespace std;int main(){ int n; cin>>n; //分配动态一维数组 int *arr=new int[n]; for(int i=0;i<n;i++) cin>>arr[i]...
2019-02-28 22:08:36 4660
原创 C++中栈和队列的使用方法(satck和queue)
栈(stack):#include <iostream>#include <stack>using namespace std;int main(){ stack<int> s; if(s.empty()) cout<<"empty"<<endl; //empty s.push(1); s.push(6)...
2019-02-28 19:55:07 378
原创 C++中stack的pop()函数返回值
int temp = s.pop(); cout<<temp<<endl;运行代码会提示错误:error C2440: “初始化”: 无法从“void”转换为“int”【全部demo】#include <iostream>#include <stack>using namespace std;int mai...
2019-02-28 19:30:31 34258
原创 C++堆排序(完整版)
堆排序步骤:(1)变为大顶堆;根节点的值大于等于其孩子节点的值。堆是一个完全二叉树,很适合用顺序结构来实现,这里我们选择数组。(2)最后一个数据和最顶部节点数据交换(最大值放在最后),然后再进行一次调整(heapify函数),变为大顶堆(此时heapsize减1)。#include <iostream>#include <vector>using name...
2019-02-28 16:22:36 3750 1
原创 C++归并排序(完整版)
#include <iostream>#include <vector>using namespace std;void merge(vector<int> &arr,int L,int mid,int R){ int *help = new int(R-L+1); int p1=L,p2=mid+1,i=0; while(p1<...
2019-02-28 16:15:22 22485 6
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人