数据结构
369pro
这个作者很懒,什么都没留下…
展开
-
内部排序(一)---基于比较的排序
// 声明:这是从之前写的算法当中抽出来做总结用的,所以部分代码是正确的,但在这里不能运行// 01 insertion_sortvoid insertion_sort(int arr[MAXSIZE], int n) // [0,n){ int i, j; for (i = 1; i < n; ++i) { int temp = arr[i]; for (j = i - 1; temp < arr[j]&& j >= 0; j--) arr[j原创 2021-12-21 16:23:18 · 112 阅读 · 0 评论 -
内部排序(二)---基于散列表
#include<iostream>#include<vector>#include<algorithm>#include<time.h>#include"queue.h"#define MIN -9999#define MAX 9999using namespace std;// 基于散列表的排序/*01 桶排序*/int* find_extremum(int* arr, int n) // 找数组中的极值(min,max){原创 2021-12-20 17:25:39 · 146 阅读 · 0 评论 -
优先级队列(二)---左式堆
#include"priority_queue.h"#include"bin_tree.h"#include<time.h>// using namespace std;#pragma oncetemplate<typename T> class leftist_heap :public bin_tree<T>,public PriorityQueue<T>{public: leftist_heap(){} T get_max() { ret原创 2021-12-15 23:47:21 · 162 阅读 · 0 评论 -
优先级队列(一)---完全二叉堆
// priority_queue.htemplate<typename T>struct priority_queue{ virtual void insert(T const& e) = 0; // 优先级队列的3个操作接口 virtual T get_max() = 0; virtual T del_max() = 0;};#include"priority_queue.h"#include"vector.h"#include<time.h>原创 2021-12-01 20:31:15 · 644 阅读 · 0 评论 -
Hashtable(二)
// dictionary.h#include<stdbool.h>#pragma oncetemplate<typename K, typename V> class Dictionary{ virtual int size() const = 0; // get,put,remove virtual V* get(K key) = 0; virtual bool put(K key, V value) = 0; virtual bool remove(K key原创 2021-11-29 10:20:04 · 59 阅读 · 0 评论 -
Hashtable(一) ---bitMap
#include<iostream>#include<string>using namespace std;class bitMap{private: int N; // size,此bitMap占多少个字节 char* M; // 存在数组M中 //void init(int n){ M = new char[(n + 7) / 8]; } // 这也叫初始化,跟个小学生一样! void ini原创 2021-11-25 15:49:53 · 579 阅读 · 0 评论 -
二叉搜索树
#include"bin_tree.h"#include<iostream>#include<stdbool.h>#pragma onceusing namespace std;template<typename T> class BST :public bin_tree<T>{protected: bin_node_posi<T> phit; // 命中(或删除)结点的父亲pu原创 2021-10-28 15:05:14 · 52 阅读 · 0 评论 -
二叉搜索树(四)---红黑树
#include"BST.h"#include"AVL.h"#include<math.h>#include<iostream>#include<time.h>#include<stdbool.h>#define IS_BLACK(p) (!(p) || (p)->color == BLACK) // p==null时外部节点视为黑色#define IS_RED(p) (!IS_BLACK(p))原创 2021-11-12 12:05:40 · 59 阅读 · 0 评论 -
二叉搜索树(三)---伸展树
#include"BST.h"#include<iostream>#include<stdbool.h>#include<time.h>using namespace std;#pragma oncetemplate<typename T> class Splay :public BST<T>{protected: bin_node_posi<T> splay(bin_node_posi<T> v)原创 2021-11-12 11:59:23 · 353 阅读 · 0 评论 -
B-树(最小I/O次数)
#include<iostream>#include<cstdio>#include<stdbool.h>#include"bin_tree.h" // 用这里面的release#include"vector.h"using namespace std;template<typename T> struct bt_node;template<typename T> using bt_node_pos原创 2021-11-06 22:33:26 · 232 阅读 · 0 评论 -
二叉搜索树(二)---AVL树
#include"BST.h"#include"bin_tree.h"#include<iostream>#include<stdbool.h>using namespace std;#pragma once#define Balanced(x) (stature((x).lchild) == stature((x).rchild))#define BalFactor(x) (stature((x).lchild) - stature((x).rchild))#de原创 2021-10-28 15:09:58 · 54 阅读 · 0 评论 -
图及其相关算法(二)
#include"Graph.h"#include"vector.h"using namespace std;#pragma once// 注意:此处是 有向边E[i][j]----------->从顶点i到顶点j的一条有向线段template<typename Tv,typename Te>class GraphMatrix :public Graph<Tv,Te> //class GraphMatrix:public Graph 继承模板类的时候记得带上模板原创 2021-10-13 21:21:32 · 71 阅读 · 0 评论 -
图及相关算法(一)
#include<cstdio>#include<iostream>#include<stdbool.h>#include<cmath>#include"Queue.h"#include"Stack.h"#define PRIO_MAX 65535#define hca(v) (fTime(v)) // highest connected ancestor#pragma once// 顶点using Vstatus =原创 2021-10-13 21:09:20 · 84 阅读 · 0 评论 -
二叉树及其实现
// 此处为"bin_tree.h"#include<cstdio>#include<iostream>#include<cstdlib>#include<cmath>#include<stack>#include<queue>#include<stdbool.h>// stature : 身高,高度#define stature(p) ((p)?(p)->height:-1)原创 2021-10-13 11:41:19 · 62 阅读 · 0 评论 -
多项式相乘(C语言)
#include<stdio.h>#include<stdlib.h>typedef struct node* list;struct node{ double coef; int expon; list next;};list create() //创建 { int n; printf("输入多项式的项数:"); scanf("%d", &n);原创 2021-10-08 20:34:15 · 2650 阅读 · 0 评论 -
栈的应用举例
#include "my_vector.h"#include<cstring>#include"list.h"#define N_OPTR 9template<typename T>class stack :public my_vector<T> // my_vector 见本人博客: c++模拟vector{ // list 见本人博客: 模拟lis原创 2021-08-24 23:14:52 · 207 阅读 · 0 评论 -
简易stack
// 简易stack#include<cstdio>#include<iostream>using namespace std;template<typename T>class stack {private: T* pstack; int capacity, top,size=0;public: stack(int c = 5):top(-1), capacity(c) { pstack = new T[capacity]; cout <原创 2021-08-16 17:29:51 · 59 阅读 · 0 评论 -
模拟list(列表)
// 模拟list#include<cstdio>#include<cstdlib>#include<iostream>using namespace std;//#define node<T> list_node<T>*;#define ptr_node list_node<T>*template<typename T> struct list_node{ T data; ptr_node pre;原创 2021-08-16 12:17:26 · 118 阅读 · 0 评论