zoukankan      html  css  js  c++  java
  • c++队列基本功能

    #include<string>
    #include<assert.h>
    #include<iostream>
    typedef int status;
    #define OK 1
    #define ERROR 0
    template<class type>
    class order_tream
    {

    public:
    order_tream(int a):size(a+1),n(0)
    {
    base =new type [a+1];
    assert(base!=0);
    front=0;
    rear=0;
    }
    int n;
    status full();//判断是否为满
    status empty();//判断是否为空
    void putin(int a);//输入
    status enqueue(type a);//进队列
    status sqqueue(type &a);//出队列
    void clear();//清空
    status out();//输出整个队列
    private:
    int rear;//尾
    int front;//头
    int size;
    type* base;
    };
    /*进队列*/
    template<class type>
    status order_tream<type>::enqueue(type a)
    {
    if( full())
    return ERROR;
    base[rear]=a;
    rear=(rear+1)%size;
    n++;
    return OK;
    }
    /*清空*/
    template<class type>
    void order_tream<type>::clear()
    {
    front=rear;
    }
    /*输入*/
    template<class type>
    void order_tream<type>::putin(int a)
    {
    type x;
    cout<<"输入开始"<<endl;
    for(int i=0;i<a;i++)
    {
    cin>>x;
    enqueue(x);
    }
    }
    /*出队列*/
    template<class type>
    status order_tream<type>::sqqueue(type& a)
    {
    if(empty())
    return ERROR;
    a=base[front];
    front=(front+1)%size;
    n--;
    return OK;
    }
    /*判断是否为空*/
    template<class type>
    status order_tream<type>::empty()
    {
    if(front==rear)
    return OK;
    else
    return ERROR;
    }
    /*判断是否为满*/
    template<class type>
    status order_tream<type>::full()
    {
    if(front==rear+1)
    return OK;
    else
    return ERROR;
    }
    /*输出整个队列*/
    template<class type>
    status order_tream<type>::out()
    {
    if(empty())
    return ERROR;
    type a;
    for(int i=0;i<n;i++)
    {
    a=base[i];
    cout<<a<<' ';
    }
    cout<<n;
    cout<<endl;
    return OK;
    }

  • 相关阅读:
    .net大文件上传
    java文件上传和下载
    文件上传系统
    plupload上传大文件
    代码坏味道之夸夸其谈的未来性
    freemarker中的substring取子串
    【翻译自mos文章】在Oracle GoldenGate中循环使用ggserr.log的方法
    3种浏览器性能測试
    SDUTOJ 2772 KMP简单应用
    C++库研究笔记--用__attribute__((deprecated)) 管理过时代码
  • 原文地址:https://www.cnblogs.com/cyh1282656849/p/5543679.html
Copyright © 2011-2022 走看看