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

华清远见第六课程作业day3

类 栈


#include <iostream>using namespace std;class Sta{
private:int *data;int top;
public:Sta():data(new int(128)){top=-1;cout<<"stack::无参构造:"<<endl;}~Sta(){delete data;cout<<"stack::析构函数:"<<this<<endl;}Sta(const Sta &other):data(new int (*other.data)),top(other.top){cout<<"拷贝构造函数"<<endl;}int empty(){return top==-1;}int full(){return top==127;}int statop(){return data[top];}int pop(){if(empty()!=1){int a=data[top];cout<<"出栈成功:"<<a<<endl;top--;return 1;}return -1;}int push(int a){if(full()!=1){top++;data[top]=a;cout<<"入栈成功:"<<endl;return 1;}return -1;}int size(){cout<<"size:"<<top<<endl;return top;}int clean(){top=0;return 0;}
};int main()
{Sta sta;sta.push(4);sta.push(5);sta.push(1);sta.push(5);sta.push(8);cout<<sta.statop()<<endl;Sta sta1=sta;return 0;
} 

类 队列

#include <iostream>using namespace std;class Sta{
private:int *data;int head;int tail;
public:Sta():data(new int(10)){head=0;tail=1;cout<<"stack::无参构造:"<<endl;}~Sta(){delete data;cout<<"stack::析构函数:"<<this<<endl;}Sta(const Sta &other):data(new int (*other.data)),head(other.head),tail(other.tail){cout<<"拷贝构造函数"<<endl;}int empty(){return head==tail;}int full(){return (tail+1+10)%10==head;}int pop(){if(empty()!=1){int a=data[head];cout<<"出队列成功:"<<a<<endl;head++;return 1;}return -1;}int push(int a){if(full()!=1){data[tail]=a;tail++;cout<<"入队列成功:"<<endl;return 1;}return -1;}int size(){int len=(tail-head+10)%10;cout<<"size:"<<len<<endl;return len;}int clean(){head=tail=0;return 0;}
};int main()
{Sta sta;sta.push(4);sta.push(5);sta.push(1);sta.push(5);sta.push(8);cout<<sta.pop()<<endl;;Sta sta1=sta;return 0;
}

http://www.lryc.cn/news/161216.html

相关文章:

  • Rabbitmq配置定义
  • 2023年数模国赛时间分配
  • kubernetes(K8S)笔记
  • vue 部署到本机IIS 部署 SPA 应用
  • 面试那些事——Java全栈
  • LINUX 文件基本管理
  • 一、认识GitHub项目 —— TinyWebServer
  • 66.C++多态与虚函数
  • 【ICer的脚本练习】通过perl脚本来检查仿真log的结果
  • 创邻科技图数据库课程走进一流高校
  • RabbtiMQ的安装与在Springboot中的使用!!!
  • 【可定制、转换时间戳】解析nc文件,并保存为csv文件
  • 介绍串行和并行两种通信方式
  • 优化爬虫效率:利用HTTP代理进行并发请求
  • 关于磁盘空间不够,导致报错 springboot内置tomcat相关的临时目录无法创建等问题,如何自定义配置 tomcat 缓存文件路径
  • Android HAL - hidl-gen
  • CGAL 数值类型
  • 建站系列(六)--- 后端开发语言
  • 王道数据结构编程题 查找
  • vue 部分知识点总结
  • 谷粒商城----ES篇
  • Redis3.2.1如何设置远程连接?允许局域网访问
  • 网络原理(二)TCP的可靠传输
  • Chat GPT 使用教学,文字创作、学习
  • Android之 Canvas绘制
  • Vue + Element UI 前端篇(十五):嵌套外部网页
  • Jabbi的Rust学习日记(二)
  • 【杂】环形时钟配色笔记
  • 会话跟踪技术学习笔记(Cookie+Session)+ HTTP学习笔记
  • 分类预测 | MATLAB实现PCA-BiLSTM(主成分双向长短期记忆神经网络)分类预测