随笔分类 -  Data Stucture/Algorithm

摘要:给定的数据为:39, 38, 12, 28, 15, 42, 44, 6, 25, 36 ,散列函数为hash(x)=x MOD 13,用线性探测法解决哈希冲突的问题,试建立哈希表,计算出查找成功和不成功时的平均查找长度(ASL)。解析:所谓的线性探查法是将散列表看成是一个环形表,若在地址d(即hash(k)=d)发生冲突,则依次探查下述地址单元:d+1,d+2,...,M-1,...d-1直到找到一个空闲地址或查找到关键码为K的结点位置。地址: 0 12 3 45 67 89101112数据: 39 12 28 15 42 44 6 25 - - 36 - 38成功次数: 1 3 1 2 . 阅读全文
posted @ 2013-05-31 15:49 Air Support 阅读(292) 评论(0) 推荐(0)
摘要:上代码: 1 #include <iostream> 2 #include <vector> 3 using namespace std; 4 5 class Item 6 { 7 private: 8 int Key; 9 public:10 Item(int value):Key(value){}11 int getKey()12 {13 return Key;14 }15 void setKey(const int &K)16 {17 this->Key = K;18 }19 };20 21... 阅读全文
posted @ 2013-05-29 19:58 Air Support 阅读(203) 评论(0) 推荐(0)
摘要:上代码:#include<iostream>#include<vector>using namespace std;class Item{private: int Key;public: Item(){} Item(int value):Key(value){} int getKey() { return Key; } void setKey(const int &K) { Key = K; }};int SeqSearch(vector<Item *> &dataList, int length, co... 阅读全文
posted @ 2013-05-28 23:46 Air Support 阅读(352) 评论(0) 推荐(0)
摘要:栈是一种比较重要的线性结构,能够解决很多困难的问题,在此写个代码小小总结一下。这里采用的实现方式是顺序结构,链式结构有待完善。。。上代码: 1 #include<iostream> 2 using namespace std; 3 4 class stack 5 { 6 private: 7 int msize; 8 int *st; 9 int top;10 public:11 stack(int size);12 bool push(int &item);13 bool pop();14 void display();15 ... 阅读全文
posted @ 2013-05-22 21:57 Air Support 阅读(253) 评论(0) 推荐(0)
摘要:队列又被称为FIFO表,即先进先出,实现队列与栈类似,存储结构有两种:顺序表和链表。这里仅仅给出队列的顺序队列实现。上代码: 1 #include<iostream> 2 using namespace std; 3 4 class Queue 5 { 6 private: 7 int front; 8 int rear; 9 int * arrq; 10 int msize;11 public:12 Queue(int size);13 bool push(int item);14 bool pop();15 void dis... 阅读全文
posted @ 2013-05-22 15:13 Air Support 阅读(273) 评论(0) 推荐(0)
摘要:01背包问题;考虑简化了的背包问题:设有一个背包可以放入的物品重量为s,现有n件物品,重量分别为 w0,w1,...,wn-1,问能否从这n件物品中选择若干件放入背包,使其重量和证号为s。如果存在一种符合上述要求的选择,则称此问题有解,否则无解。使用递归方法,则此问题轻而易举的就解决了: 1 #include<iostream> 2 using namespace std; 3 4 int *w; 5 bool knap(int s, int n) 6 { 7 if (s == 0) 8 { 9 return true ;10 }11 if((... 阅读全文
posted @ 2013-05-22 10:42 Air Support 阅读(213) 评论(0) 推荐(0)