游戏网站seo怎么做,太原网站建设方案报价,一元购物网站怎么做,湖南营销类网站设计1 自行封装一个栈的类#xff0c;包含私有成员属性#xff1a;栈的数组、记录栈顶的变量
成员函数完成#xff1a;构造函数、析构函数、拷贝构造函数、入栈、出栈、清空栈、判空、判满、获取栈顶元素、求栈的大小
2 自行封装一个循环顺序队列的类#xff0c;包含…1 自行封装一个栈的类包含私有成员属性栈的数组、记录栈顶的变量
成员函数完成构造函数、析构函数、拷贝构造函数、入栈、出栈、清空栈、判空、判满、获取栈顶元素、求栈的大小
2 自行封装一个循环顺序队列的类包含私有成员属性存放队列的数组、队头位置、队尾位置
成员函数完成构造函数、析构函数、拷贝构造函数、入队、出队、清空队列、判空、判满、求队列大小
1
#include iostream
#define MAX 128using namespace std;
class Stack_s
{
private:int *pnew int[MAX];//栈的数组int top;//记录栈顶的变量
public://构造函数Stack_s(int t-1){topt;cout无参构造函数endl;}//析构函数~Stack_s(){coutStack::析构函数endl;}//拷贝构造函数Stack_s(const Stack_s other):p(other.p),top(other.top){cout拷贝构造函数endl;}//入栈int stack_push(int e){if(stack_full()){cout入栈失败endl;return -1;}top;p[top]e;cout入栈成功endl;return 0;}//出栈int stack_pop(){if(stack_empty()){cout出栈失败endl;return -1;}int ep[top];top--;coute 出栈成功endl;return 0;}//清空栈int stack_delete(){while(top!-1){stack_pop();}delete [] p;pnullptr;cout清空栈成功endl;return 0;}//判空bool stack_empty(){if(top-1){cout栈空endl;return 1;}return 0;}//判满bool stack_full(){if(topMAX-1){cout栈满了endl;return 1;}return 0;return 0;}//获取栈顶元素int stack_gettop(){cout栈顶元素是p[top]endl;return 0;}//栈的大小void stack_getsize(){cout栈的大小为top1endl;}void show(int i){coutp[i] ;}
};
int main()
{Stack_s s1;int e;int s;s1.stack_empty();cout请输入要入栈的个数;cins;for(int i0;is;i){cout请输入要入栈的元素;cine;s1.stack_push(e);}s1.stack_gettop();s1.stack_getsize();for(int i0;is;i){s1.show(i);}coutendl;s1.stack_delete();return 0;
}2
#include iostream
#define MAX 128using namespace std;
class Queue_q
{
private:int *pnew int[MAX];//队列的数组int tail;//记录队尾元素int head;//记录对头元素
public://构造函数Queue_q(int t0){headt;tailt;cout无参构造函数endl;}//析构函数~Queue_q(){coutStack::析构函数endl;}//拷贝构造函数Queue_q(const Queue_q other):p(other.p),tail(other.tail),head(other.head){cout拷贝构造函数endl;}//入队int queue_push(int e){if(queue_full()){cout入队失败endl;return -1;}p[tail]e;tail;cout入队成功endl;return 0;}//出队int queue_pop(){if(queue_empty()){cout出队失败endl;return -1;}int ep[head];head(head1)%MAX;coute 出队成功endl;return 0;}//清空队列int queue_delete(){while(head!tail){queue_pop();}delete [] p;pnullptr;cout清空队列成功endl;return 0;}//判空bool queue_empty(){if(headtail){cout队列空endl;return 1;}return 0;}//判满bool queue_full(){if((tail1)0){cout队列满了endl;return 1;}return 0;}//队列的大小void queue_getsize(){int size;size(tail-headMAX)%MAX;cout队的大小为sizeendl;}void show(int i){coutp[i] ;}
};
int main()
{Queue_q q1;int e;int s;q1.queue_empty();cout请输入要入队的个数;cins;for(int i0;is;i){cout请输入要入队的元素;cine;q1.queue_push(e);}q1.queue_getsize();for(int i0;is;i){q1.show(i);}coutendl;q1.queue_delete();return 0;
}思维导图