随笔分类 -  数据结构与算法

优先队列(非模板函数,是int)
摘要:发现了一个可能是书里的错误,在swim函数中while检测的条件void priorityQueue::Swim(size_t t){ inArr[0]=inArr[t]; while (inArr[t/2]#ifndef LUPRIORITY_QUEUE#define ... 阅读全文

posted @ 2016-08-14 16:12 雪峰00 阅读(113) 评论(0) 推荐(0)

队列简要实现,是queue,不是dequeue
摘要:#ifndef MYQUEUE_H#define MYQUEUE_Hstruct Node{ int data; Node *next;};class LUqueue{public: LUqueue(); ~LUqueue(); void Push(int data); in... 阅读全文

posted @ 2016-07-24 21:09 雪峰00 阅读(143) 评论(0) 推荐(0)

栈实现,不是用template做的.
摘要:用单链表来实现栈,插入和删除的部分很有意思。写完这个感觉突然理解了书上说的适配器的观点,类就是这样,不管你底层实现是什么,表现成什么就好了,是一个黑盒。头文件Mystack.h#ifndef MYSATCK_H#define MYSTACK_Hstruct Node { in... 阅读全文

posted @ 2016-07-24 20:33 雪峰00 阅读(88) 评论(0) 推荐(0)

杨辉三角,一个vector实现,不复制,不用队列。
摘要:昨晚写到纸上,今天晚上调通,本来想要动态数组,但是发现这块的知识还欠缺,用着有问题。自己基础知识一直有问题,真是心急,要学习的知识好多,都不知道先学哪个。整个代码效率应该很低,因为进行了大量的判断。目前没有在网上搜到一样的代码,有点小虚荣。#include#include u... 阅读全文

posted @ 2016-07-13 23:22 雪峰00 阅读(146) 评论(0) 推荐(0)

桶排序
摘要:#include#includeint MaxValue(std::vectorb);void BarrelSort(int c[], std::vectorb){ int max = MaxValue(b); int* a=new int [max+1]; for (int... 阅读全文

posted @ 2016-04-19 20:09 雪峰00 阅读(70) 评论(0) 推荐(0)

AVL树单选转和双旋转
摘要:看了好几天树了,也算有点心得。学树,必须要图。这里有两篇里的博客,在结合书,我用的是《数据结构与算法分析C++版》就可以了。http://blog.csdn.net/a454042522/article/details/8591421http://blog.csdn.net/... 阅读全文

posted @ 2016-04-02 14:07 雪峰00 阅读(329) 评论(0) 推荐(0)

二分查找(改)
摘要:2016/3/25二分查找,应该是面试里比较简单但是也会问道的问题。这个代码,是我初看见二分查找的原理时写的,用的递归。好吧,有明显的错误,就是当寻找的值不在数组中时会越界。int FindX(const vector& a,int left,int right ,int k... 阅读全文

posted @ 2016-03-25 11:43 雪峰00 阅读(138) 评论(0) 推荐(0)

采用递归求数组里面求最大子序列的算法(手绘图解)
摘要:本文改编自我在知乎的回答。http://t.cn/RqPi9FO先上代码。private static int maxSumRec( int [ ] a, int left, int right ) { int maxLeftBorderSum = 0, ... 阅读全文

posted @ 2016-03-25 08:41 雪峰00 阅读(257) 评论(0) 推荐(0)

导航