main.cpp
上传用户:shunfadg
上传日期:2022-07-28
资源大小:4k
文件大小:2k
- #include "deque.h"
- #include <fstream>
- #include <cassert>
- using namespace std;
- int main(){
- int i,data, len;
- cout << "1. EnQueueTail and DeQueueHead:n" << endl;
- cout << "The data in the file is: n";
- ifstream fin1("data.txt");
- assert(fin1);
- DeQue<int> que1;
- while (!fin1.eof()) {
- assert(fin1 >> data);
- cout << data << " ";
- que1.EnDeQueTail(data);
- }
- cout << endl;
- fin1.close();
- cout << "nUse EnQueueTail for each data in the file, nthen the queue is:n";
- cout << que1 << endl;
- cout << "nUse DeQueueHead in turn, the result is:"<<endl;
- len = que1.Length();
- for(i = 0; i < len; i++){
- data=que1.DeDeQueHead();
- cout << "Delete " << data << ", then the queue is:n";
- cout << que1 << endl;
- }
- cout << "n==================================================n";
- cout << "2. EnQueueHead and DeQueueTail:" << endl;
- cout << "The data in the file is: n";
- ifstream fin2("data.txt");
- assert(fin2);
- DeQue<int> que2;
- while (!fin2.eof()){
- assert(fin2 >> data);
- cout << data << " ";
- que2.EnDeQueHead(data);
- }
- cout << endl;
- fin2.close();
- cout << "nUse EnQueueHead for each data in the file, nthen the queue is:n";
- cout << que2 << endl;
- cout << "nUse DeQueueTail in turn, the result is:"<<endl;
- len = que2.Length();
- for(i = 0; i < len; i++){
- data=que2.DeDeQueTail();
- cout << "Delete " << data << ", then the queue is:n";
- cout << que2 << endl;
- }
- cout << "n==================================================n";
- cout << "3. stack push:" << endl;
- cout << "The data in the file is: n";
- ifstream fin3("data.txt");
- assert(fin3);
- DeQue<int> que3;
- while (!fin3.eof()){
- assert(fin3 >> data);
- cout << data << " ";
- que3.EnDeQueHead(data);
- }
- cout << endl;
- fin3.close();
- cout << "nStack push used EnDeQueHead for each data in the file, nthen the queue is:n";
- cout << que3 << endl;
- cout << "nStack pop used DeDeQueHead in turn, the result is:"<<endl;
- len = que3.Length();
- while(!que3.IsEmpty()){
- data=que3.DeDeQueHead();
- cout << "Pop " << data << ", then the stack is:n";
- cout << que3 << endl;
- }
- return 0;
- }