数据结构与算法
文章平均质量分 75
夜行歌
这个作者很懒,什么都没留下…
展开
-
C语言实现栈
/*参考《数据结构与 算法分析:C语言描述》*/ #include#includetypedef int ElemType;typedef struct Stack{ ElemType data; struct Stack *next;}Stack,*pStack;pStack InitStack(){ pStack S=(pStack)m原创 2014-12-23 12:24:56 · 424 阅读 · 0 评论 -
C语言实现队列
#include #include typedef int ElemType;typedef struct Queue{ElemType data;struct Queue *next;}Queue,*pQueue;pQueue CreateQueue(){pQueue p=(pQueue)malloc(sizeof(Queue));p->next=原创 2014-12-26 13:41:22 · 316 阅读 · 0 评论 -
快速排序
快速排序是由C.A.R.Hoare在1960年发明,是基于分治模式的。以下内容来自《算法导论》下面是对一个子数组A[p..r]排序的分治过程的三个步骤: 实例:#include #include #include using namespace std;void exch(int *原创 2015-03-21 15:58:18 · 476 阅读 · 0 评论 -
auto_ptr实现
//参考《More Effective C++》#include using namespace std;templateclass autoptr{ private: T* r; public: autoptr(T* a=nullptr):r(a){} //不能使用默认拷贝构造函数 autoptr(autopt原创 2015-07-16 13:59:20 · 325 阅读 · 0 评论 -
二叉堆实现二
堆可以视为一棵完全二叉树,树的每一层都是被填满的,最后一层可能除外,所以堆可以用数组来表示。对于数组中任意位置i上的元素,其左儿子在位置i*2+1,其右儿子在位置i*2+2上,其父节点在位置(i+1)/2-1处。二叉堆有两种:最大堆和最小堆。最大堆中,除根结点外(其无父结点),每个结点的关键字都不大于其父结点的关键字。最小堆中,除根结点外,每个结点的关键字都不小于其父结点的关键字。原创 2015-10-14 22:36:45 · 500 阅读 · 0 评论 -
二叉堆实现一
//参考>#include #include using namespace std;vector heap;void max_heap(int i) {//使以i为根的子树成为最大堆 int l=2*i+1, r=2*(i+1),s=heap.size(),lgst=i; if(lheap[i]) lgst=l; if(rheap[lgst]) lgst原创 2015-10-01 09:14:21 · 364 阅读 · 0 评论 -
List实现
#include#includeusing namespace std;template struct list_node{ T key; list_node *next,*pre;};templatestruct list_iterator{ using ref=list_iterator; using list_type=list_原创 2015-07-16 13:57:20 · 283 阅读 · 0 评论 -
C语言实现二叉查找树
#include #include #include typedef struct BiTree{int data;struct BiTree *lch;struct BiTree *rch;}BiTree,*pBiTree;/*插入节点*/pBiTree Insert(pBiTree T,int data){pBiTree temp原创 2014-11-07 14:26:00 · 381 阅读 · 0 评论