摘要: 头文件 1 #ifndef _顺序队列_H 2 #define _顺序队列_H 3 4 5 6 template <class T> 7 class Queue 8 { 9 public: 10 Queue(int queueCapacity=10); 11 bool IsEmpty() const; 12 T& Front() const;//用来读取队首数据,只看不删 13 T& Rear() const; 14 void Push(const T &item);//队尾加 15 void Pop();//队首删 1... 阅读全文
posted @ 2012-03-27 23:51 uniquews 阅读(216) 评论(0) 推荐(0) 编辑
摘要: 头文件 1 #include <iostream> 2 #include"二叉树.h" 3 4 using namespace std; 5 6 int main() 7 8 { 9 BinaryTree<char> tree;10 TreeNode<char> 加,减,乘,除,a,b,c,d,e;11 12 加.data = '+';13 减.data = '-';14 乘.data = '*';15 除.data = '/';16 17 a.data = 'A&# 阅读全文
posted @ 2012-03-27 23:50 uniquews 阅读(132) 评论(0) 推荐(0) 编辑
摘要: 头文件 1 #include<iostream> 2 #include"linkedStack.h" 3 4 using namespace std; 5 6 int main() 7 { 8 9 10 cout << "测试链式栈"<< endl;11 LinkedStack<int> s;12 s.Push(10);13 cout << s.Top() << endl;14 s.Push(20);15 cout << s.Top() << endl;16 阅读全文
posted @ 2012-03-27 23:49 uniquews 阅读(152) 评论(0) 推荐(0) 编辑
摘要: 头文件 1 #ifndef LINKEDSTACK_H 2 #define LINKEDSTACK_H 3 4 template<class T> class LinkedStack;//前置声明 5 6 template<class T> 7 class ChainNode 8 { 9 10 friend LinkedStack<T>;11 private:12 ChainNode(const T& theData, ChainNode *n = 0):data(theData), link(n){}//构造函数13 T data;14 Chain 阅读全文
posted @ 2012-03-27 23:47 uniquews 阅读(199) 评论(0) 推荐(0) 编辑
摘要: 头文件 1 #ifndef _QUEUELI_H 2 #define _QUEUELI_H 3 4 template<class Object> 5 class Queue 6 { 7 8 public: 9 Queue(); 10 ~Queue(); 11 12 bool isEmpty() const; 13 const Object & getFront() const;//返回队首数据 14 void enqueue(const Object & x);//在队尾加入数据 15 Object dequeue();/... 阅读全文
posted @ 2012-03-27 23:46 uniquews 阅读(152) 评论(0) 推荐(0) 编辑
摘要: MyStack.hView Code 1 #ifndef _MYSTACK_H 2 #define _MYSTACK_H 3 4 #include "MyUtil.h" 5 6 template<class T> 7 class MyStack 8 { 9 10 public:11 MyStack(int stackCapacity=10);//默认值是1012 ~MyStack();13 14 bool IsEmpty() const;15 T& Top() const;16 void Push(const T& item);17 voi... 阅读全文
posted @ 2012-03-27 23:44 uniquews 阅读(316) 评论(0) 推荐(0) 编辑
摘要: View Code 1 #include <iostream> 2 3 using namespace std; 4 5 class DblList;// 前置声明 6 7 class DblListNode 8 { 9 friend class DblList;10 public:11 int data;12 DblListNode *llink, *rlink;13 14 };15 16 class DblList17 {18 19 public:20 DblList()21 {22 first = new DblListNo... 阅读全文
posted @ 2012-03-27 23:41 uniquews 阅读(198) 评论(0) 推荐(0) 编辑
摘要: View Code 1 #include<iostream> 2 #include<bitset> 3 #include<string> 4 5 using namespace std; 6 7 int main() 8 9 {10 11 bitset<32> a;//a可以放32位二进制12 13 cout << a <<endl;14 15 16 bitset<16> b(0xffff);//1111 1111 ...17 18 cout << b << endl;19 20 bit 阅读全文
posted @ 2012-03-27 23:36 uniquews 阅读(280) 评论(0) 推荐(0) 编辑
摘要: View Code 1 #include<iostream> 2 #include<queue> 3 4 int main() 5 { 6 7 using namespace std; 8 9 priority_queue<int,vector<int>> pq;//默认是vector 最大值优先级队列10 11 //谓词12 priority_queue<int,deque<int>,greater<int>> pq2; //加上greater 就是最小值优先级队列13 14 pq.push(10);15 p 阅读全文
posted @ 2012-03-27 23:32 uniquews 阅读(158) 评论(0) 推荐(0) 编辑
摘要: View Code 1 #include<iostream> 2 #include<queue> 3 #include<list> 4 #include<deque> 5 6 //queue不能用vector 7 //队列和堆栈都不能修改数据的值,没有迭代器 8 9 using namespace std;10 11 12 int main()13 {14 queue<int, deque<int>> a;15 queue<int,list<int>> b;16 queue<int> q 阅读全文
posted @ 2012-03-27 23:31 uniquews 阅读(789) 评论(0) 推荐(0) 编辑
摘要: View Code 1 #include <iostream> 2 #include<stack> 3 #include<vector> 4 #include<list> 5 6 using namespace std; 7 8 9 int main()10 11 {12 13 stack<int,deque<int>> a;14 stack<int,vector<int>> b;15 stack<int,list<int>> c;16 stack<int> d; 阅读全文
posted @ 2012-03-27 23:30 uniquews 阅读(158) 评论(0) 推荐(0) 编辑
摘要: View Code 1 #include <iostream> 2 #include<set> 3 4 using namespace std; 5 typedef multiset<int> MSETINT;//set插入比vector稍慢 他不是顺序容器 不能再找到数据后直接修改,需删除后再添加新数据。 6 int main() 7 { 8 9 MSETINT a;10 11 a.insert(43);12 a.insert(78);13 a.insert(78);14 a.insert(-1);15 a.insert(124);1... 阅读全文
posted @ 2012-03-27 23:29 uniquews 阅读(122) 评论(0) 推荐(0) 编辑
摘要: View Code 1 #include <iostream> 2 #include<set> 3 4 5 using namespace std; 6 7 8 template <typename Container>//原因是 a 和ma 的类型不一样,所以要做成模板函数 container还可以显示vector等 9 void PrintContents(const Container & c);10 11 12 int main()13 {14 15 16 set<int> a;//set容器会自动进行排序17 multiset& 阅读全文
posted @ 2012-03-27 23:28 uniquews 阅读(126) 评论(0) 推荐(0) 编辑
摘要: View Code 1 #include<iostream> 2 #include<list> 3 4 5 using namespace std; 6 7 void PrintListContent(const list<int>& listInput); 8 9 int main()10 {11 12 std::list<int> a;13 14 a.push_front(5);15 a.push_front(9);16 a.push_front(21);17 a.push_front(16);18 a.push_front(8);. 阅读全文
posted @ 2012-03-27 23:27 uniquews 阅读(128) 评论(0) 推荐(0) 编辑
摘要: View Code 1 #include<iostream> 2 #include<list> 3 4 using namespace std; 5 6 void PrintListContent(const list<int>& listInput); 7 8 int main() 9 {10 11 12 std::list<int> a;13 a.push_front(4);14 a.push_front(3);15 16 list<int>::iterator iElementValueTwo;17 18 iElemen 阅读全文
posted @ 2012-03-27 23:25 uniquews 阅读(127) 评论(0) 推荐(0) 编辑
摘要: View Code 1 #include <iostream> 2 #include<list> 3 4 using namespace std; 5 6 void PrintListContent(const list<int>& listInput); 7 8 int main() 9 {10 11 12 13 list<int> a;14 list<int> b;15 list<int>::iterator iter;16 17 b.push_back(100);18 b.push_back(200);19 阅读全文
posted @ 2012-03-27 23:23 uniquews 阅读(152) 评论(0) 推荐(0) 编辑
摘要: View Code 1 #include<iostream> 2 #include<deque> 3 #include<algorithm> 4 5 int main() 6 7 { 8 using namespace std; 9 10 deque<int> a;11 12 a.push_back(3);13 a.push_back(4);14 a.push_back(5);15 16 a.push_front(2);17 a.push_front(1);18 a.push_front(0);19 20 for(size_t nCount = 阅读全文
posted @ 2012-03-27 23:19 uniquews 阅读(162) 评论(0) 推荐(0) 编辑
摘要: View Code 1 #include<iostream> 2 #include<vector> 3 #include<string> 4 5 using namespace std; 6 7 8 int main() 9 10 {11 12 vector<int> ivec;//空!大小为零13 cout << ivec.size() <<endl;14 15 cout<<"请输入5个整数"<<endl;16 int k;17 for(vector<int>::s 阅读全文
posted @ 2012-03-27 23:15 uniquews 阅读(166) 评论(0) 推荐(0) 编辑