当前位置: 首页 > news >正文

网站建设 论坛wordpress 关闭warning

网站建设 论坛,wordpress 关闭warning,新建网站的评估,内容型网站day3_C 思维导图用C的类完成数据结构 栈的相关操作用C的类完成数据结构 循环队列的相关操作 思维导图 用C的类完成数据结构 栈的相关操作 stack.h #ifndef STACK_H #define STACK_H#include <iostream> #include <cstring>using namespace std;typedef int datat…

day3_C++

  • 思维导图
  • 用C++的类完成数据结构 栈的相关操作
  • 用C++的类完成数据结构 循环队列的相关操作

思维导图

请添加图片描述

用C++的类完成数据结构 栈的相关操作

stack.h

#ifndef STACK_H
#define STACK_H#include <iostream>
#include <cstring>using namespace std;typedef int datatype;#define MAX 5class Stack
{
public:/*构造函数*/Stack();/*拷贝构造函数*/Stack(const Stack& others);/*析构函数*/~Stack();/*判满 true 满 */bool is_full();/*判满 true 空*/bool is_empty();/*入栈*/void in_stack(datatype e);/*出栈*/datatype out_stack();/*清空栈*/void clear_stack();/*求栈顶元素*/datatype get_stackTop_E();/*求栈的大小*/void get_stackSize();private:int top;datatype *data;
};#endif // STACK_H

stack.cpp

#include "stack.h"Stack::Stack():data(new int[MAX]),top(-1)
{memset(this->data,0,MAX);//在堆区申请max个int大小的空间cout<<"栈容器初始化成功"<<endl;
}Stack::Stack(const Stack& others):data(new int[MAX]),top(others.top)
{//深拷贝,将堆区内容也拷贝进来for(int i = 0;i<MAX-1;i++){this->data[i] = others.data[i];}cout<<"拷贝完成"<<endl;
}Stack::~Stack()
{//释放堆区数据delete []data;cout<<"析构完成"<<endl;
}bool Stack::is_full()
{if(this->top ==MAX-1)return true;elsereturn false;
}bool Stack::is_empty()
{if(this->top == -1)return true;elsereturn false;
}void Stack::in_stack(datatype e)
{if(this->is_full()==false){this->top++;this->data[this->top] = e;cout<<"入栈成功"<<endl;}else{cout<<"入栈失败,栈满"<<endl;}
}datatype Stack::out_stack()
{if(this->is_empty()==false){datatype temp = this->data[this->top];this->top--;return temp;}else{cout<<"出栈失败,栈空"<<endl;return NULL;}
}void Stack::clear_stack()
{if(this->is_empty()==false){this->top=-1;cout<<"清空成功"<<endl;}else{cout<<"栈空,无需清理"<<endl;}
}datatype Stack::get_stackTop_E()
{if(this->is_empty()==true)return NULL;return this->data[this->top];
}void Stack::get_stackSize(){cout<<"栈中有元素 "<<this->top+1<<"个"<<endl;
}

用C++的类完成数据结构 循环队列的相关操作

queue.h

#ifndef QUEUE_H
#define QUEUE_H
#include <iostream>
#include <cstring>using namespace std;typedef int datatype;
#define MAX 5class Queue
{public:/*构造函数*/Queue();/*拷贝构造函数*/Queue(const Queue& others);/*析构函数*/~Queue();/*判满 true 满 */bool is_full();/*判满 true 空*/bool is_empty();/*入队*/void in_queue(datatype e);/*出队*/datatype out_queue();/*清空队*/void clear_queue();/*求队的大小*/void get_queueSize();private:datatype *data;int font;int tail;
};#endif // QUEUE_H

queue.cpp

#include "queue.h"Queue::Queue():data(new int [MAX]),tail(0),font(0)
{memset(this->data,0,MAX);cout<<"循环队列初始化成功"<<endl;
}Queue::Queue(const Queue& others):data(new int[MAX]),font(others.font),tail(others.tail)
{//深拷贝int f = this->font;int t = this->tail;while ((f+MAX)%MAX==t) {this->data[f] = others.data[f];f++;}cout<<"拷贝完成"<<endl;
}bool Queue::is_full()
{if((this->tail+1)%MAX == this->font){return true;}return false;
}bool Queue::is_empty()
{if(this->font == this->tail){return true;}return false;
}Queue::~Queue()
{//释放堆区数据delete []data;cout<<"析构完成"<<endl;
}void Queue::in_queue(datatype e)
{if(this->is_full() == true){cout<<"队列满了"<<endl;return ;}this->data[this->tail] = e;this->tail =  (this->tail+1)%MAX;cout<<"入队成功"<<endl;
}
/*出队*/
datatype Queue::out_queue()
{if(this->is_empty() == true){cout<<"队列空,无元素"<<endl;return NULL;}int temp =  this->data[this->font];this->font = (this->font+1)%MAX;return temp;
}void Queue::clear_queue()
{if(this->is_empty() == true){cout<<"队列空,无元素"<<endl;return;}this->font = 0;this->tail = 0;
}void Queue::get_queueSize()
{cout<<"队列的大小是:" <<(this->tail-this->font+MAX)%MAX<<endl;
}
http://www.yayakq.cn/news/380242/

相关文章:

  • 设计素材图库广州seo培训
  • 做贸易的都有什么网站门户网站 制作多少钱
  • 沈阳医疗网站建设杭州市建设信用网
  • 门户网站建设方案费用交换链接营销的经典案例
  • 网站的用户体验主要有那些类型张家港网站建设哪家好
  • 广东省网站建设网站公司电子商务网站建设策划书
  • 烟台建站程序html5做的网站
  • 学习网站开发思路济南网站建设 伍际网络
  • 梧州网站建设推荐服务器创建网站
  • 网站建设的具体过程甲马营seo网站优化的
  • 济南网站建设哪家强 资海外贸营销型网站建设公司
  • 建设通类型网站叫啥免费制作企业宣传视频app
  • 做个网站大概多少钱网站做外部链接
  • 内蒙古城乡建设厅网站域名怎么建设网站
  • 泸州网站seo国内十大软件外包公司
  • python node 网站开发销售方案网站
  • 一篇关于大学网站建设与管理的论文微网站建设公司首选
  • 网站 建设 后台管理程序房地产网站制作公司
  • 深圳网站开发外包公司cc域名网站需要备案吗
  • 北京智能网站建设哪里有网络规划设计方案实例
  • 网站建设共享ip网络推广方案范例
  • 邢台专业网站建设推荐品牌设计公司简介
  • 无锡新吴区住房和建设交通局网站网站建设文化如何
  • 怎样一个域名做两个网站建设银行的财务网站
  • wordpress5.0启多站点wordpress手机端侧边工具栏
  • 建立网站大约多少钱如何让百度不收录网站
  • 咸宁 网站建设黄冈论坛大小事
  • 购物网站建设精英高端网站建设注意
  • 怎样做 云知梦 网站 付费网站这是我看过尺度最大的哔哩哔哩
  • 做响应式网站对设计图的要求开发一个oa系统多少钱