1.队列
2.栈
#include<iostream>
#define MAX 20
typedef int datatype;
using namespace std;
class Queue
{
private:
datatype data[MAX];
int front;
int tail;
public:
Queue()
{
front=0;
tail=0;
}
bool empty();
bool full();
int size();
void push(datatype e);
void pop();
void show();
};
bool Queue::empty()
{
return front==tail?true:false;
}
bool Queue::full()
{
return (tail+1)%MAX==front ? true:false;
}
int Queue::size()
{
return ((tail-front)+MAX)%MAX;
}
void Queue::push(datatype e)
{
if(full())
{
cout<<"has full"<<endl;
return ;
}
else
{
data[tail]=e;
tail=(tail+1)%MAX;
}
}
void Queue::pop()
{
if(empty())
{
cout<<"was empty"<<endl;
return;
}
else
{
front=(front+1)%MAX;
}
}
void Queue::show()
{
if(empty())
{
return ;
}
for(int i=front;i!=tail;i=(i+1)%MAX)
{
cout<<data[i]<<" ";
}
cout<<endl;
}
class Stack
{
private:
datatype data[MAX];
int top;
public:
Stack()
{
top=-1;
}
bool empty();
bool full();
int size();
void push(datatype e);
void pop();
void show();
};
bool Stack::empty()
{
return top==-1?true:false;
}
bool Stack::full()
{
return top>=MAX?true:false;
}
int Stack::size()
{
return top+1;
}
void Stack::push(datatype e)
{
if(full()){cout<<"has full"<<endl;return;}
top++;
data[top]=e;
if(top>MAX){cout<<"already full"<<endl;}
}
void Stack::pop()
{
if(empty()){cout<<"empty"<<endl;return;}
top--;
}
void Stack::show()
{
if(empty()){cout<<"empty"<<endl;return;}
for(int i=0;i<top;i++)
{
cout<<data[i]<<" ";
}
cout<<endl;
}
class student
{
private:
string m_name;
int m_age;
double m_score;
public:
student(){}
student(string name,int age,double score):m_name(name),m_age(age),m_score(score){}
void show()
{
cout<<"name ="<<m_name<<" age= "<<m_age<<" score= "<<m_score<<endl;
}
};
class party
{
private:
string m_party_activty;
string m_org;
public:
party(){}
party(string party_act,string org):m_party_activty(party_act),m_org(org){}
void show()
{
cout<<"party_activty ="<<m_party_activty<<" org= "<<m_org<<endl;
}
};
class student_lea: public party,public student
{
private:
string m_pro;
public:
student_lea(){}
student_lea(string name,int age,double score,string party_activty,string org,string pro)
:student(name,age,score),party(party_activty,org),m_pro(pro){}
void show()
{
student::show();
party::show();
cout<<"pro= "<<m_pro<<endl;
}
};
int main()
{
Queue q1;
q1.push(10);
q1.push(9);
q1.push(8);
q1.push(7);
q1.pop();
q1.push(6);
q1.show();
Stack s1;
s1.push(10);
s1.push(10);
s1.push(10);
s1.push(10);
s1.push(10);
s1.push(10);
s1.push(10);
s1.show();
student_lea s5("hah",18,96.3,"11","22","33");
s5.show();
}