码迷,mamicode.com
首页 > 其他好文 > 详细

Queue2

时间:2014-05-26 02:19:36      阅读:213      评论:0      收藏:0      [点我收藏+]

标签:style   class   blog   c   code   java   

bubuko.com,布布扣
 1 #include <iostream>
 2 using namespace std;
 3 template <class T>
 4 class Queue
 5 {
 6 private:
 7     struct node
 8     {
 9         T data;
10         node * next;
11         node():next(NULL) {}
12         node(T d):data(d),next(NULL) {}
13     };
14     node * Front;
15     node * rear;
16     node * head;
17 
18 public:
19     int Count;
20     Queue()
21     {
22         node * tem = new node();
23         Front = tem;
24         rear  = tem;
25         head = tem;
26         Count = 0;
27     }
28     bool isEmpty()
29     {
30         return Count == 0;
31     }
32     void makeEmpty()
33     {
34         while(Front != NULL)
35         {
36             node * p = Front;
37             Front = Front -> next;
38             delete p;
39         }
40         Count = 0;
41     }
42     void enQueue(T d)
43     {
44         node * tem = new node(d);
45         rear -> next = tem;
46         rear = rear -> next;
47         Count++;
48     }
49     void printQueue()
50     {
51         node * cur = Front;
52         while(cur != NULL)
53         {
54             cout<<cur -> data<<" ";
55             cur = cur -> next;
56         }
57     }
58     void outQueue()
59     {
60         cout<<Front->data<<" ";
61         node * p = Front;
62         Front = Front -> next;
63         delete (p);
64     }
65     T getTop()
66     {
67         return Front->data;
68     }
69     void init()
70     {
71         Front = Front -> next;
72         rear = rear -> next;
73     }
74 };
75 int main()
76 {
77     Queue<int> dusk;
78 
79     for(int i = 0 ; i < 100 ; i++)
80     {
81         dusk.enQueue(i);
82     }
83     dusk.init();
84     dusk.printQueue();
85     cout<<endl;
86     cout<<dusk.getTop();
87 
88 }
bubuko.com,布布扣

 

Queue2,布布扣,bubuko.com

Queue2

标签:style   class   blog   c   code   java   

原文地址:http://www.cnblogs.com/Duskcl/p/3749411.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!