队列  0.1
数据结构_第4章
test0.cc
Go to the documentation of this file.
1 /****************************************************
2  * @file test0.cc
3  * @author Guorui Wei (313017602@qq.com)
4  * @brief 测试队列类的基本功能
5  * @version 0.1
6  * @date 2020-04-06
7  *
8  * @copyright Copyright (c) 2020
9  *
10  * See the file LICENSE in the top directory of this distribution for
11  * more information.
12  *
13  ****************************************************/
14 
15 #include "Queue.h"
16 #include <iostream>
17 #include <string>
18 
24 struct data_t
25 {
26  size_t _id;
27  std::string _name;
28 
35  data_t(size_t id = 0, std::string name = "name")
36  : _id(id), _name(name) {}
37 
42  void prn() const
43  {
44  std::cout << "_id: " << _id << " _name: " << _name << std::endl;
45  }
46 };
47 
60 int main(int argc, char const *argv[])
61 {
62  Queue::seqQueue<data_t> seqQ(1);
64  Queue::vecQueue<data_t> vecQ(1);
65  data_t _Data[5] = {1, 2, 3, 4, 5};
66 
67  // 入队测试: 复制/移动
68  for (int i = 0; i < 5; ++i)
69  {
70  seqQ.enQueue(data_t(i));
71  linQ.push(data_t(i));
72  vecQ.enQueue(_Data[i]);
73  }
74 
75  std::cout << "\n入队5个元素的size: \n"
76  << seqQ.size() << ' ' << linQ.size() << ' ' << vecQ.size() << std::endl;
77 
78  // 出队测试
79  std::cout << "\nseqQ出队: \n";
80  while (!seqQ.empty())
81  seqQ.deQueue().prn();
82 
83  std::cout << "\nlinQ出队: \n";
84  while (!linQ.isEmpty())
85  {
86  auto tmp = linQ.front();
87  linQ.pop();
88  tmp.prn();
89  }
90 
91  std::cout << "\nvecQ出队: \n";
92  while (!vecQ.empty())
93  {
94  vecQ.deQueue().prn();
95  }
96 
97  std::cout << "\n所有元素出队后的size: \n"
98  << seqQ.size() << ' ' << linQ.size() << ' ' << vecQ.size() << std::endl;
99 
100  return 0;
101 }
Queue.h
data_t
用于测试队列的简单类
Definition: test0.cc:24
data_t::data_t
data_t(size_t id=0, std::string name="name")
Construct a new data t object.
Definition: test0.cc:47
Queue::seqQueue
循环队列类
Definition: seqQueue.hh:46
Queue::linkQueue
Ӷ
Definition: linkQueue.hh:46
Queue::vecQueue::size
size_type size() const
Returns the number of elements in the queue.
Definition: vecQueue.hh:229
Queue::linkQueue::front
reference & front()
Returns a reference to the next element in the queue.
Definition: linkQueue.hh:276
main
int main(int argc, char const *argv[])
测试队列类的基本功能
Definition: test0.cc:60
Queue::seqQueue::empty
bool empty() const
Test whether container is empty.
Definition: seqQueue.hh:228
Queue::linkQueue::isEmpty
virtual bool isEmpty() const
жӿ
Definition: linkQueue.hh:153
Queue::vecQueue::empty
bool empty() const
Test whether container is empty.
Definition: vecQueue.hh:223
data_t::prn
void prn() const
print
Definition: test0.cc:54
Queue::vecQueue
队头位置固定的队列类
Definition: vecQueue.hh:46
Queue::linkQueue::push
void push(const value_type &val)
Inserts a new element at the end of the queue, after its current last element.
Definition: linkQueue.hh:300
data_t::_name
std::string _name
std::string
Definition: test0.cc:39
Queue::vecQueue::enQueue
virtual void enQueue(const_reference &x)
入队一个元素
Definition: vecQueue.hh:128
Queue::linkQueue::pop
void pop()
Removes the next element in the queue.
Definition: linkQueue.hh:322
Queue::vecQueue::deQueue
virtual value_type deQueue()
出队一个元素
Definition: vecQueue.hh:138
Queue::seqQueue::deQueue
virtual value_type deQueue()
出队一个元素
Definition: seqQueue.hh:143
Queue::seqQueue::enQueue
virtual void enQueue(const_reference &x)
入队一个元素
Definition: seqQueue.hh:133
Queue::linkQueue::size
size_type size() const
Returns the number of elements in the queue.
Definition: linkQueue.hh:270
Queue::seqQueue::size
size_type size() const
Returns the number of elements in the queue.
Definition: seqQueue.hh:234
data_t::_id
size_t _id
size_t
Definition: test0.cc:38