数据结构
single 君
求大佬carry
展开
-
数组中的第K大元素:快速选择和大根堆小根堆,库大根堆
听说这玩意儿是面试重点。。。比如快速选择:你不能说快排,说快排就寄,要用经过优化的快速选择算法:class Solution {public: int quickselect(vector<int>& nums, int l,int r,int ksmall){ //if(l=r)return nums[l]; int q=rand()%(r-l+1)+l; int key=nums[q]; swap(nums原创 2022-03-16 22:49:54 · 498 阅读 · 0 评论 -
(最详细合理代码)C++实现图的深度优先遍历、广度优先遍历和拓扑排序算法
图的邻接矩阵和邻接表矩阵void createGraph(vector<vector<int>>& edge, vector<vector<int>>& edge1,int start, int end, vector<int> inDegree) { edge[start][end] = 1; edge1[start].push_back(end);}//打印存储的图void displayGraph(vector&l原创 2020-12-10 02:25:34 · 967 阅读 · 0 评论 -
C++顺序检索、二分检索,并统计比较次数,体现最好、最差、平均三种情况
//实验四#include <iostream>using namespace std;//顺序查找与二分查找//顺序查找就是循环//二分查找//使用前提:数据必须排序int ordersearch(int* a, int x, int n, int count[]){ int k; for (int i=0; i < n; i++) { count[0]++; if (a[i] == x) {原创 2020-11-25 20:59:21 · 1570 阅读 · 0 评论 -
八大排序算法比较次数交换次统计程序
#include <iostream>#include<assert.h>using namespace std;template<typename E>inline void swap(E A[], int i, int j) { E temp = A[i]; A[i] = A[j]; A[j] = temp;}template <typename E>void insertsort(E A[], int n,int count1[],i原创 2020-11-19 19:12:20 · 4266 阅读 · 0 评论 -
数据结构八种排序算法(原始精简版)只需一个iostream库就可以运行(
template<typename E>inline void swap(E A[], int i, int j) { E temp = A[i]; A[i] = A[j]; A[j] = temp;}template <typename E>void insertsort(E A[], int n) { // Insertion Sort for (int i = 1; i < n; i++) // Insert i’th record for (int原创 2020-11-19 02:15:30 · 109 阅读 · 1 评论