⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 queue2.h

📁 using queue to solve traffic matter by C++ in linux environment
💻 H
字号:
// FILE: queue2.h
// TEMPLATE CLASS PROVIDED: Queue<Item> (a queue of items)
//   The template parameter, Item, is the data type of the items in the Queue.
//   It may be any of the C++ built-in types (int, char, etc.), or a class
//   with a default constructor, a copy constructor, and assignment operator.
//
// CONSTRUCTOR for the Queue<Item> template class:
//   Queue( )
//     Postcondition: The Queue has been initialized as an empty Queue.
//
// MODIFICATION MEMBER FUNCTIONS for the Queue<Item> template class:
//   void insert(const Item& entry)
//     Postcondition: A new copy of entry has been inserted at the rear of the
//     Queue.
//
//   Item get_front( )
//     Precondition: size( ) > 0.
//     Postcondition: The front item of the Queue has been popped and returned.
//
// CONSTANT MEMBER FUNCTIONS for the Queue<Item> template class:
//   size_t size( ) const
//     Postcondition: The return value is the total number of items in the
//     Queue.
//
//   bool is_empty( ) const
//     Postcondition: The return value is true if the Queue is empty.
//
//   Item peek( ) const
//     Precondition: size( ) > 0.
//     Postcondition: Return value is the front item of the Queue
//     (but the Queue is unchanged).
//
// VALUE SEMANTICS for the Queue<Item> template class:
//   Assignments and the copy constructor may be used with Queue<Item> 
//   objects.
//
// DYNAMIC MEMORY USAGE by the Queue<Item> template class:
//   If there is insufficient dynamic memory, then the following functions
//   call new_handler: the constructors, insert, and the assignment operator.

#ifndef QUEUE2_H
#define QUEUE2_H
#include <stdlib.h>  // Provides size_t
#include "link2.h"   // Linked list toolkit

    template <class Item>
    class Queue
    {
    public:
        // CONSTRUCTORS and DESTRUCTOR
        Queue( );
        Queue(const Queue& source);
        ~Queue( );
        // MODIFICATION functions
        void insert(const Item& entry);
        Item get_front( );
        void operator =(const Queue& source);
        // CONSTANT functions
        size_t size( ) const { return count; }
        bool is_empty( ) const { return (count == 0); }
	Item peek( ) const;
    private:
        Node<Item> *front_ptr;  // Points to front of queue
        Node<Item> *rear_ptr;   // Points to rear of queue
        size_t count;           // Total number of items in the queue
    };

#include "queue2.template" // Include the implementation
     
#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -