摘要: 栈是一种比较重要的线性结构,能够解决很多困难的问题,在此写个代码小小总结一下。这里采用的实现方式是顺序结构,链式结构有待完善。。。上代码: 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 阅读(246) 评论(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 阅读(262) 评论(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 阅读(205) 评论(0) 推荐(0) 编辑