泛型隊列實現檔案C++

來源:互聯網
上載者:User

 

//queue.cpptemplate<class T>void Queue<T> ::m_copyElement (const Queue &queue){QueueItem<T> * scan = queue.m_head ;while (scan != NULL){push(scan ->m_item) ;scan = scan ->m_next ;}}template<class T> template<typename Iter>void Queue<T> ::m_copyElement (Iter beg, Iter end){while (beg != end){push(*beg) ;++beg ;}}template<class T>void Queue<T> ::m_destroy (void){while (!isEmpty()){pop() ;}}template<class T> template<typename Iter>Queue<T> ::Queue (Iter beg, Iter end): m_head(0), m_tail(0){m_copyElement(beg, end) ;}template<class T>Queue<T> ::Queue (const Queue & queue): m_head(0), m_tail(0){m_copyElement(queue) ;}template<class T>Queue<T> & Queue<T> ::operator = (const Queue & queue){m_destroy() ;m_copyElement(queue) ;return *this ;}template<class T>Queue<T> ::~Queue (void){m_destroy() ;}template<class T> template<typename Iter>void Queue<T> ::assign (Iter beg, Iter end){m_destroy() ;m_copyElement(beg, end) ;}template<class T>bool Queue<T> ::isEmpty (void) const{return NULL == m_head ;}template<class T>T & Queue<T> ::front (void){return m_head ->m_item ;}template<class T>const T & Queue<T> ::front (void) const{return m_head ->m_item ;}template<class T>void Queue<T> ::push (const T & item){QueueItem<T> * newItem = new QueueItem<T>(item) ;if (!isEmpty()){m_tail ->m_next = newItem ;m_tail = newItem ;}else{m_head = m_tail = newItem ;}}template<class T>void Queue<T> ::pop (void){QueueItem<T> * pTemp = m_head ;m_head = m_head ->m_next ;delete pTemp ;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.