📄 queue2.template
字号:
// FILE: queue2.template// TEMPLATE CLASS IMPLEMENTED: Queue<Item> (see queue2.h for documentation)// This file is included in the header file, and not compiled separately.// INVARIANT for the Queue ADT:// 1. The number of items in the Queue is stored in the member variable// count.// 2. The items in the queue are stored in a linked list, with the front of// the queue stored at the head node, and the rear of the queue stored at// the final node.// 3. The member variable front_ptr is the head pointer of the linked list of// items. For a non-empty queue, the member variable rear_ptr is the// tail pointer of the linked list; for an empty list, we don't care// what's stored in rear_ptr.#include <assert.h> // Provides assert#include <stdlib.h> // Provides size_t#include "link2.h" // Linked list toolkittemplate <class Item>Queue<Item>::Queue( )// Library facilities used: stdlib.h{ count = 0; front_ptr = NULL;}template <class Item>Queue<Item>::Queue(const Queue<Item>& source)// Library facilities used: link2.h{ count = source.count; list_copy(source.front_ptr, front_ptr, rear_ptr);}template <class Item>Queue<Item>::~Queue( ){ list_clear(front_ptr);}template <class Item>void Queue<Item>::operator =(const Queue<Item>& source)// Library facilities used: link2.h{ if (source.front_ptr == front_ptr) // Handle self-assignment return; list_clear(front_ptr); count = source.count; list_copy(source.front_ptr, front_ptr, rear_ptr);}template <class Item>void Queue<Item>::insert(const Item& entry)// Library facilities used: link2.h{ if (is_empty( )) { // Insert first entry list_head_insert(front_ptr, entry); rear_ptr = front_ptr; } else { list_insert(rear_ptr, entry); rear_ptr = rear_ptr->link; } count++;}template <class Item>Item Queue<Item>::get_front( )// Library facilities used: assert.h{ Item answer; assert(!is_empty( )); answer = front_ptr->data; list_head_remove(front_ptr); count--; return answer;}template <class Item>Item Queue<Item>::peek( ) const // Library facilities used: assert.h{ assert(!is_empty( )); return front_ptr->data;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -