![](https://img-blog.csdnimg.cn/20201014180756738.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
数据结构与算法
文章平均质量分 55
chosen13
这个作者很懒,什么都没留下…
展开
-
交换算法swap
#include #define SWAP(x,y,t) ((t) = (x), (x) = (y), (y) = (t)) // 这是定义了一个宏,宏函数定义的,这是C语言的方法,using namespace std;void swap(int *px, int *py); // 这是把交换做成了一个函数,用指针,void swap(int &t1, int &t2);原创 2016-03-30 14:48:35 · 342 阅读 · 0 评论 -
循环列表
#ifndef _LIST_H#define _LIST_H// 循环列表,template class List;template class ListIterator;templateclass ListNode{ friend class List; friend class ListIterator;private: Type data; // 节点里的数据,原创 2016-04-08 21:04:03 · 236 阅读 · 0 评论 -
哈希映射
#ifndef HASHMAP_H_#define HASHMAP_H_#include templateclass HashMap // 哈希映射 速度最快,{public: HashMap(int size = 100) : arr(size) { currentSize = 0; } void Put(const Key & k,const Value & v)原创 2016-04-25 20:49:44 · 701 阅读 · 0 评论 -
双向链表
#include using namespace std;class DblList; // 前置声明,class DblListNode{ friend class DblList;public: int data; DblListNode *llink, *rlink;};class DblList{public: DblList() { first原创 2016-04-09 21:21:28 · 222 阅读 · 0 评论 -
顺序容器 list
#include #include using namespace std;void PrintListContents(const list& listInput);int main(){ list a; list b; list::iterator iter; b.push_back(2); b.push_back(8); PrintListContents(原创 2016-04-13 19:27:56 · 303 阅读 · 0 评论 -
顺序容器 list 2
#include #include using namespace std;void PrintListContents(const list& listInput);int main(){ list a; a.push_front(3); a.push_front(6); list::iterator iElementValueTwo; iElementValueT原创 2016-04-13 19:37:15 · 249 阅读 · 0 评论 -
图 - 邻接矩阵
#include #define MAX_VERTS 20using namespace std;class Vertex{public: Vertex(char lab) { Label = lab; }private: char Label; // 定义字符,};class Graph // 这是一个图,{public: Graph(); ~Graph()原创 2016-04-26 21:39:01 · 292 阅读 · 0 评论 -
基数排序
#include #include using namespace std;int maxdigit(int data[], int n){ int d = 1; int p = 10; for(int i = 0; i < n; ++i) { while(data[i] >= p) { p *= 10; ++d; } } return d;}原创 2016-04-14 20:05:02 · 226 阅读 · 0 评论 -
图 - 邻接表
#include #include using namespace std;class Vertex{public: char Label; Vertex(char lab) { Label = lab; }};ostream& operator<<(ostream& out, const Vertex& v) // 这个是输出操作符重载,{ cout << v.La原创 2016-04-27 20:24:55 · 234 阅读 · 0 评论 -
广度 / 深度优先搜索
#include #include // 堆栈,#include // 队列,#define MAX_VERTS 20 using namespace std; class Vertex { public: Vertex(char lab) { Label = lab; wasVisited = false; } pub原创 2016-04-27 21:44:08 · 200 阅读 · 0 评论 -
链式栈
#ifndef LINKEDSTACK_H#define LINKEDSTACK_Htemplate class LinkedStack;templateclass ChainNode{ friend class LinkedStack;private: ChainNode(const T& theData, ChainNode *n = 0) : data(theData原创 2016-04-11 22:03:39 · 246 阅读 · 0 评论 -
数据结构 二叉树
#ifndef _二叉树_H#define _二叉树_H#include #include // 队列,template class BinaryTree;templateclass TreeNode // 这个类用来表示子节点,{public: TreeNode() { leftChild = NULL; rightChild = NULL; } T原创 2016-04-15 21:25:19 · 178 阅读 · 0 评论 -
二叉查找树
#ifndef 二叉查找树_H_#define 二叉查找树_H_#include // 在头文件中不要用using namespace std; 容易产生错误,enum Boolean {FALSE,TRUE};templateclass Element{public: Type key; // key是键值, // 添加更多的数据,};template cla原创 2016-04-19 20:37:05 · 187 阅读 · 0 评论 -
红黑树-高级的二叉查找树
#ifndef WRAPPER_H_#define WRAPPER_H_#include "Except.h"templateclass Cref{public: Cref() : obj(NULL) {} explicit Cref(const Object & x) : obj(&x) {} const Object & get() const { if(isNu原创 2016-04-23 19:10:44 · 266 阅读 · 0 评论 -
堆的操作
#ifndef MAXHEAP_H_#define MAXHEAP_H_templateclass MaxHeap{public: MaxHeap(int mx = 10); virtual ~MaxHeap(); bool IsEmpty(); void Push(const T&); void Pop(); const T& Top() const; // Top就原创 2016-04-23 22:01:47 · 182 阅读 · 0 评论 -
链表迭代器
#ifndef _LIST_H#define _LIST_Htemplate class List;template class ListIterator;templateclass ListNode{ friend class List; friend class ListIterator;private: Type data; // 节点里的数据, ListNode原创 2016-04-08 20:12:07 · 270 阅读 · 0 评论 -
链式队列
#ifndef QUEUELI_H#define QUEUELI_Htemplateclass Queue{public: Queue(); ~Queue(); bool isEmpty() const; const Object & getFront() const; void enqueue(const Object & x); Object dequeue();原创 2016-04-12 15:25:49 · 179 阅读 · 0 评论 -
链表2
#ifndef _LIST_H#define _LIST_Htemplate class List;templateclass ListNode{ friend class List;private: Type data; // 节点里的数据, ListNode *link; // 指向下一个节点的数据, ListNode(Type);};templateclas原创 2016-04-07 21:29:57 · 182 阅读 · 0 评论 -
最简单的算法-冒泡排序
#include using namespace std;void BubbleSort(int list[], int n); // 这个是函数的声明,int main(){ int a[] = {2,4,6,8,0,1,3,5,7,9}; BubbleSort(a,10); for(int k = 0; k < 10; k++) cout << a[k] <<原创 2016-03-30 19:19:46 · 223 阅读 · 0 评论 -
算法:选择排序
#include using namespace std;void SelectSort(int *a, const int n); int main() { int x[] = {1,3,5,7,9,0,2,4,6,8}; SelectSort(x,10); for(int k = 0; k < 10; k++) cout << x[k] << " "; cou原创 2016-03-30 20:00:52 · 200 阅读 · 0 评论 -
算法 :顺序查找
#include using namespace std;int SequentialSearch(int *a, const int n, const int x);int main(){ int m[] = {2,4,6,8,0,1,3,5,7,9}; int 结果; int num = 3; 结果=SequentialSearch(m,10,num); if(结果原创 2016-03-30 20:46:19 · 180 阅读 · 0 评论 -
算法:折半查找或二分查找
#include using namespace std;int BinarySearch(int *a, const int x, const int n); // 二分查找即折半查找int BinSearch(int *a, const int x, const int n); // 这是函数的声明,int main(){ int t[] = { 1,2,3,4,5,6,原创 2016-03-30 21:26:01 · 320 阅读 · 0 评论 -
递归的小例子
#include using namespace std;void doA() // 递归就是自己调用自己,{ cout << "爱你,小崔" << endl; doA();}int main(){ doA(); // 一直输出 爱你,小崔 return 0;}原创 2016-03-30 21:34:20 · 188 阅读 · 0 评论 -
递归
#include using namespace std;// 递归就是自己调用自己,迭代就是循环,void doA(){ cout << "爱你,小崔" << endl; doA();}long 阶乘(int n){ if(n == 0) return 1; else return n * 阶乘(n - 1);}long 阶乘2(int n){ lon原创 2016-03-30 21:51:58 · 275 阅读 · 0 评论 -
递归与迭代的折半查找
#include using namespace std;int BinarySearch_I(int *a, const int x, const int n);int BinarySearch_R(int *a, const int x, const int left, const int right);int main(){ int m[] = {1,2,3,4,5,6,7原创 2016-03-31 13:13:10 · 228 阅读 · 0 评论 -
排列组合 用递归
#include using namespace std;int c1 = 0; // 调用的次数,int c2 = 0; // 返回的次数,void show(char *p, int m){ for(int i = 0; i <= m; i++) cout << p[i]; cout << endl;}void Permutations(char *p, co原创 2016-03-31 20:53:39 · 243 阅读 · 0 评论 -
算法:插入排序
#include using namespace std;templatevoid InsertionSort(T *a, int n);templatevoid InsertionSort_2(T *a, int n);int main(){ double x[] = {2.1,4,6.3,0,1,3,5}; InsertionSort(x,7); for(int i原创 2016-04-05 19:45:28 · 170 阅读 · 0 评论 -
算法: 快速算法
#include using namespace std;templatevoid QuickSort(T *a, const int left, const int right) // 这是代表的是左右边的下标,{ if(left < right) { //选枢轴 int i = left; int j = right + 1; // 为什么要加1, int p原创 2016-04-05 20:23:31 · 316 阅读 · 0 评论 -
算法:归并排序
#include #include using namespace std;templatevoid Merge(T *initList,T *mergedList, const int l, const int m, const int n) // l和m是下标,n是个数,{ int i1,i2,iResult; for(i1 = l, i2 = m + 1, iResult原创 2016-04-05 21:42:51 · 168 阅读 · 0 评论 -
数据结构:栈
#ifndef _MYUNTIL_#define _MYUNTIL_templatevoid ChangeSize1D(T* &a, const int oldSize, const int mewSize);templatevoid ChangeSize1D(T* &a, const int oldSize, const int mewSize){ if(newSize = 0原创 2016-04-06 20:36:04 · 198 阅读 · 0 评论 -
数据结构:队列- 顺序队列
#ifndef _顺序队列_H#define _顺序队列_Htemplate // 类模板,class Queue{public: Queue(int queueCapacity=10); bool IsEmpty() const; T& Front() const; // 队尾的数据, T& Rear() const; void Push(const T& item);原创 2016-04-06 21:52:29 · 274 阅读 · 0 评论 -
链表--单链表
#ifndef THREELETTERNODE_H#define THREELETTERNODE_Hclass ThreeLetterList{private: //嵌套类, class ThreeLetterNode { public: char data[4]; // 一个数据域, ThreeLetterNode *link; // 链接域, }; Thre原创 2016-04-07 19:16:26 · 181 阅读 · 0 评论 -
堆排序
#ifndef MAXHEAP_H_#define MAXHEAP_H_templateclass MaxHeap{public: MaxHeap(int mx = 10); virtual ~MaxHeap(); bool IsEmpty(); void Push(const T&); void Pop(); const T& Top() const; // Top就原创 2016-04-24 21:44:33 · 158 阅读 · 0 评论