基本数据结构:链式队列

  队列(Queue)是只允许在一端进行插入,而在另一端进行删除的运算受限的线性表
  (1)允许删除的一端称为队头(Front)。
  (2)允许插入的一端称为队尾(Rear)。
  (3)当队列中没有元素时称为空队列。
  (4)队列亦称作先进先出(First In First Out)的线性表,简称为FIFO表。

     队列的修改是依先进先出的原则进行的。新来的成员总是加入队尾(即不允许"加塞"),每次离开的成员总是队列头上的(不允许中途离队),即当前"最老的"成员离队。


队列定义如下:

[cpp]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. #ifndef LINKEDQUEUE  
  2. #define LINKEDQUEUE  
  3. #include <iostream>  
  4. using std::ostream;    
  5.   
  6. template <typename T>  
  7. class LinkedQueue  
  8. {  
  9. private:  
  10.     struct Node  
  11.     {  
  12.         T data;//值域  
  13.         Node *next;//后继  
  14.   
  15.         Node(Node *node = nullptr) : next(node)  
  16.         {  
  17.   
  18.         }  
  19.   
  20.         Node(const T &value,Node *node = nullptr) : data(value),next(node)  
  21.         {  
  22.   
  23.         }  
  24.     };  
  25.   
  26.     Node *front;//头  
  27.     Node *rear;//尾  
  28.   
  29. public:  
  30.   
  31.     LinkedQueue() : front(nullptr),rear(nullptr)  
  32.     {  
  33.   
  34.     }  
  35.   
  36.     ~LinkedQueue()  
  37.     {  
  38.         makeEmpty();  
  39.     }  
  40.   
  41.     void makeEmpty()//队列清空  
  42.     {  
  43.         Node *p ;  
  44.         while(front)   
  45.         {  
  46.             p = front;  
  47.             front = front->next;  
  48.             delete p;  
  49.         }  
  50.     }  
  51.   
  52.     bool enQueue(const T &value)//进队  
  53.     {  
  54.         if(isEmpty())  
  55.         {  
  56.             front = rear = new Node(value);  
  57.               
  58.             return front == nullptr ? true : false;  
  59.         }  
  60.         else  
  61.         {  
  62.             rear->next = new Node(value);  
  63.             rear = rear->next;  
  64.   
  65.             return rear == nullptr ? true : false;  
  66.         }  
  67.     }  
  68.   
  69.     bool deQueue(T &x)//出队  
  70.     {  
  71.         if(isEmpty())  
  72.         {  
  73.             return false;  
  74.         }  
  75.         else  
  76.         {  
  77.             Node *p = front;  
  78.             x = front->data;  
  79.             front = front->next;  
  80.             delete p;  
  81.             return true;  
  82.         }  
  83.     }  
  84.   
  85.     bool isEmpty() const  
  86.     {  
  87.         return front == nullptr;  
  88.     }  
  89.   
  90.     bool getFront(T &x)  
  91.     {  
  92.         if(isEmpty())  
  93.         {  
  94.             return false;  
  95.         }  
  96.         else  
  97.         {  
  98.             Node *p = front;  
  99.             x = front->data;  
  100.             return true;  
  101.         }  
  102.     }  
  103.   
  104.     int size()  
  105.     {  
  106.         Node *p = front;  
  107.         int k = 0;  
  108.         while(p)  
  109.         {  
  110.             p = p->next;  
  111.             ++k;  
  112.         }  
  113.   
  114.         return k;  
  115.     }  
  116.   
  117.     friend ostream & operator<<(ostream &out,LinkedQueue<T> &lq)  
  118.     {  
  119.         Node *p = lq.front;  
  120.         for(int i = 1; i <= lq.size(); i++)  
  121.         {  
  122.             out << "#" << i <<":" << p->data << endl;  
  123.             p = p->next;  
  124.         }  
  125.   
  126.         return out;  
  127.     }  
  128. };  
  129.   
  130. #endif  

测试代码如下:

[cpp]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. #include "linkedQueue.h"  
  2. #include <fstream>  
  3. using std::cin;    
  4. using std::cout;    
  5. using std::endl;    
  6. using std ::ifstream;  
  7.   
  8.   
  9. int main()  
  10. {  
  11.     ifstream fin("data.txt");  
  12.     LinkedQueue<int> que;  
  13.     int data;  
  14.     while (!fin.eof()){  
  15.         fin >> data;  
  16.         que.enQueue(data);  
  17.     }  
  18.     cout << "The queue in the file is:\n" << que << endl;  
  19.     que.getFront(data);  
  20.     cout << "The front in the queue is: " << data << endl;  
  21.   
  22.     cout << "Delete the front in turn, the result is:" << endl;  
  23.     int len = que.size();  
  24.     for(int i = 0; i < len; i++){  
  25.         que.deQueue(data);  
  26.         cout << "Delete " << data << ", then the queue is:\n";  
  27.         cout << que << endl;  
  28.     }  
  29.   
  30.     system("pause");  
  31.     return 0;  
  32. }  
内容概要:该研究通过在黑龙江省某示范村进行24小时实地测试,比较了燃煤炉具与自动/手动进料生物质炉具的污染物排放特征。结果显示,生物质炉具相比燃煤炉具显著降低了PM2.5、CO和SO2的排放(自动进料分别降低41.2%、54.3%、40.0%;手动进料降低35.3%、22.1%、20.0%),但NOx排放未降低甚至有所增加。研究还发现,经济性和便利性是影响生物质炉具推广的重要因素。该研究不仅提供了实际排放数据支持,还通过Python代码详细复现了排放特征比较、减排效果计算和结果可视化,进一步探讨了燃料性质、动态排放特征、碳平衡计算以及政策建议。 适合人群:从事环境科学研究的学者、政府环保部门工作人员、能源政策制定者、关注农村能源转型的社会人士。 使用场景及目标:①评估生物质炉具在农村地区的推广潜力;②为政策制定者提供科学依据,优化补贴政策;③帮助研究人员深入了解生物质炉具的排放特征和技术改进方向;④为企业研发更高效的生物质炉具提供参考。 其他说明:该研究通过大量数据分析和模拟,揭示了生物质炉具在实际应用中的优点和挑战,特别是NOx排放增加的问题。研究还提出了多项具体的技术改进方向和政策建议,如优化进料方式、提高热效率、建设本地颗粒厂等,为生物质炉具的广泛推广提供了可行路径。此外,研究还开发了一个智能政策建议生成系统,可以根据不同地区的特征定制化生成政策建议,为农村能源转型提供了有力支持。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值