Queue class-Chained storage

Source: Internet
Author: User

Code:

linkqueue.hpp//Queue class #pragma once#include "linklist.hpp" template <typename t>class linkqueue{public:linkqueue ( ); ~linkqueue ();p ublic:int Clear (); int append (t &t); int Retieve (t &t); int header (t &t); int length (); Protected:linklist<t> *m_list;}; Template <typename T>linkqueue<t>::linkqueue () {m_list = new linklist < T >;} Template <typename T>linkqueue<t>::~linkqueue () {clear ();d elete m_list;m_list = NULL;} Template <typename t>int linkqueue<t>::clear () {T t;while (M_list->getlen () > 0) {m_list->del (0, T) ;} return 0;} Template <typename t>int linkqueue<t>::append (t &t) {return M_list->insert (T, M_list->getlen ()) ;} Template <typename t>int linkqueue<t>::retieve (t &t) {return M_list->del (M_list->getlen ()-1, T) ;} Template <typename t>int linkqueue<t>::header (t &t) {return m_list->get (0, t);} Template <typename t>int linkqueue<t>::length () {return M_LIST-&GT;getlen ();} 

main.cpp//Queue Class Test program # include <iostream> #include <cstdio> #include "linkqueue.hpp" using namespace std; struct Student{char name[32];int age;}; void Play () {Student S1, s2, s3;s1.age = 21;s2.age = 22;s3.age = 23; Linkqueue<student> LQ; Create Queue lq.append (S1); Into the queue lq.append (S2); Lq.append (S3); Student Tmp;lq.header (TMP); cout << "header of the queue:" << tmp.age << endl;cout << "Length of queue : "<< lq.length () << endl;while (lq.length () > 0) {lq.retieve (TMP); cout << tmp.age <<";} cout << endl;lq.clear ();} int main () {play (); return 0;}

for the design and implementation of the linked list class, see my other two articles:C + + linked list template classes,Linear chain-type storage design and implementation-API implementation

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Queue class-Chained storage

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.