C++ 顺序栈和循环队列

顺序栈

#include 
#include 

using namespace std;

template 
class zhan
{
private:
     T* data;   //指针
     int top;       //栈顶
     int size;      //容量

public:
     //构造
     zhan(int d=10)
     {
         size = d;
         top=-1;
         data = new T[size];
     }

     //析构
     ~zhan()
     {
         delete []data;
     }

     //入栈
     void ru(T d)
     {
         if(top+1>=size)
         {
             cout<<"栈已满"< s(10);
    s.ru(1);
    s.ru(2);
    s.ru(3);

    cout<

循环队列

#include 
#include 

using namespace std;

template 
class duilie
{
private:
     T* data;      //指针
     int wei;       //队尾
     int tou;      //队头
     int size;

public:
     //构造
     duilie(int size=10)
     {
         tou=0;
         wei=0;
         data=new T[size];
     }

     //析构
     ~duilie()
     {
         delete []data;
     }

     //插入
     bool charu(int d)
     {
         if(tou==(wei+1)%size)
         {
             cout<<"队列已满"< s(10);

    s.charu(5);
    s.charu(6);
    s.charu(7);

    cout<

你可能感兴趣的:(c++)