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

建设网站有什么风险软文标题

建设网站有什么风险,软文标题,网站建设报价明细表,github page做公司网站北邮22信通一枚~ 跟随课程进度每周更新数据结构与算法的代码和文章 持续关注作者 解锁更多邮苑信通专属代码~ 上一篇文章: 北邮22信通:(9)实验1 题目六:模拟内存管理(搬运官方代码)_青…

北邮22信通一枚~   

跟随课程进度每周更新数据结构与算法的代码和文章 

持续关注作者  解锁更多邮苑信通专属代码~

上一篇文章:

北邮22信通:(9)实验1 题目六:模拟内存管理(搬运官方代码)_青山如墨雨如画的博客-CSDN博客

下一篇文章:

目录

3.2.1顺序栈

代码部分:

运行结果:

遇到问题:

运行结果:

3.2.2链式栈:

代码部分:

运行结果:


***闲话***

老规矩,书上干净完整代码,拿去用!

最近一直在忙感冒忙修电脑忙期中考试(          有点断更(

顺序栈里边两个栈共用一个存储空间的代码正在更新中  敬请期待

下面就是实现顺序栈和链式栈的代码,其实原理都差不多,甚至主函数都一样(

对小编个人而言更喜欢用链表a 不想判断顺序栈可恶的开始终止位置

然后虚拟数据类型我写了一个student,比较简单的数据类型嘞,方便大家看

其他的想到啥再补充啥  有问题或者我写的有不对的地方欢迎评论区指正!

**********

3.2.1顺序栈

代码部分:

#include <iostream>
using namespace std;
struct student
{int ID;string name;
};
ostream& operator<<(ostream& output, student& stu)
{output << stu.ID << " " << stu.name;return output;
}
const int stacksize = 1024;
template <class temp>
class seqstack
{
public:seqstack() { top = -1; }void push(temp x);temp pop();temp gettop();bool empty() { return top == -1 ? true : false; }//判断栈空时的条件:top==-1?
private:temp data[stacksize];int top;
};template<class temp>
void seqstack<temp>::push(temp x)
{if (this->top > stacksize - 1)throw"上溢";this->top++;this->data[this->top] = x;
}template <class temp>
temp seqstack<temp>::pop()
{if (empty())throw"下溢";this->top--;return this->data[this->top + 1];
}template<class temp>
temp seqstack<temp>::gettop()
{if (empty())throw"下溢";return this->data[this->top];
}
int main()
{try{system("color 0A");student x[5] = { {1,"zhang"},{2,"wang"},{3,"li"},{4,"zhao"},{5,"meng"} };seqstack<student> seq1;cout << "显示栈内是否为空?" << endl;cout << seq1.empty();cout << endl << endl;cout << "数据传输中……" << endl;for (int i = 0; i < 5; i++)seq1.push(x[i]);cout << "显示栈内是否为空?" << endl;cout << seq1.empty();cout << endl << endl;student stutemp;for (int i = 0; i < 5; i++){cout << "出栈元素的信息:" << endl;stutemp = seq1.pop();cout << stutemp;cout << endl;cout << "此时栈顶元素信息:" << endl;stutemp = seq1.gettop();cout << stutemp;cout << endl << endl;}cout << endl << "现在重新判断栈是否为空:" << endl;cout << seq1.empty();}catch (const char* a){cout << a << endl;}return 0;
}

运行结果:

遇到问题:

发现没有执行程序第79、80行

原因:catch到了const char*类型的异常,程序终止运行。

需要注意的是,一定要catch (const char*)!!!不要catch(string)否则你的程序跑不起来

我们把68行循环终止条件改成3

运行结果:

 

3.2.2链式栈:

代码部分:

#include <iostream>
using namespace std;
struct student
{int ID;string name;
};
ostream& operator<<(ostream& output, student& stu)
{output << stu.ID << " " << stu.name;return output;
}
template <class temp>
struct node
{temp data;node<temp>* next;
};template <class temp>
class linkstack
{
public:linkstack() { top = NULL; }~linkstack();void push(temp x);temp pop();temp gettop();bool empty(){return top == NULL ? true : false;}
private:node<temp>* top;
};template <class temp>
void linkstack<temp>::push(temp x)
{node<temp>* p = new node<temp>;p->data = x;p->next = this->top;this->top = p;
}template<class temp>
temp linkstack<temp>::pop()
{if (empty())throw "下溢";temp x = this->top->data;node<temp>* p = this->top;this->top = this->top->next;delete p;return x;
}template<class temp>
linkstack<temp>::~linkstack()
{while (this->top != NULL){node<temp>* p = this->top;this->top = this->top->next;delete p;}
}template<class temp>
temp linkstack<temp>::gettop()
{if (empty())throw"下溢";return this->top->data;
}
int main()
{try{system("color 0A");student x[5] = { {1,"zhang"},{2,"wang"},{3,"li"},{4,"zhao"},{5,"meng"} };linkstack<student> linklist1;cout << "显示栈是否为空?" << endl;cout << linklist1.empty();cout << endl << endl;cout << "数据传输中……" << endl;for (int i = 0; i < 5; i++)linklist1.push(x[i]);cout << "显示栈是否为空?" << endl;cout << linklist1.empty();cout << endl << endl;student stutemp;for (int i = 0; i < 5; i++){cout << "出栈元素信息:" << endl;stutemp = linklist1.pop();cout << stutemp;cout << endl;cout << "此时栈顶元素信息:" << endl;stutemp = linklist1.gettop();cout << stutemp;cout << endl << endl;}cout << "现在重新判断栈是否为空:" << endl;cout << linklist1.empty();}catch (const char*a){cout << a << endl;}return 0;
}

运行结果:

(将pop循环改成循环到3,同理,会显示最后一行“现在重新判断栈是否为:”) 

http://www.yidumall.com/news/83045.html

相关文章:

  • 非经营备案网站能贴放广告么天津seo标准
  • 长沙找人做企业网站文案全网推广哪家正宗可靠
  • 网站开发需求分析包括哪些方面淘宝关键词排名怎么查
  • linux系统如何做网站南京seo推广公司
  • 平台推广员是干嘛的中国seo关键词优化工具
  • 外国网站在内地做seo厦门网站建设
  • 五屏网站建设哪家有百度指数分析案例
  • 可以自己做免费网站吗代运营电商公司排行榜
  • 电商食品网站建设百度搜索关键词技巧
  • 德州企业做网站多少钱开源cms建站系统
  • 信誉好的镇江网站优化全网最低价24小时自助下单平台
  • 领手工在家做的网站成都专门做网站的公司
  • h5建站网站安徽关键词seo
  • 独立网站建站公司申请网站怎样申请
  • 肯德基网站开发seo运营是什么意思
  • 伊春网站推广seo的基本步骤
  • 做影视网站须要注意什么seo实战优化
  • 做赌场网站代理东莞产品网络推广
  • 网站开发建设方案的主要内容包括自己怎么创建网站
  • 如何建设网站兴田德润简介呢年轻人不要做网络销售
  • 网站建设更新不及时互联网营销公司
  • 电脑购物网站模板短视频运营
  • 网站开发培训广西win7优化大师
  • 动画制作专业就业前景郑州企业网站seo
  • 日常生活用品设计seo优化排名怎么做
  • 做网页链接网站企业网站优化推广
  • 做网站分流潍坊住房公积金
  • 网站规划与开发实训室建设方案网站seo优化运营
  • 网站图片代码企业营销策划论文
  • 太原网站建设加q.479185700温州seo优化