- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
03使用堆栈决编程问题
Pop操作就是从堆栈的顶部取出数据,即从链栈的起始处删除一个结点。要进行Pop操作,需要执行以下的步骤: 3. 出栈操作:T Pop( ) 用顺序栈解决堆栈的编程问题——对顺序栈进行操作 步骤 1 2 3 4 操作 检查堆栈中是否含有元素,如果没有,停止操作;否则执行下面的步骤 获取栈顶指示器top所指向结点的值 将栈顶指示器top指向单链表中下一个结点 栈元素个数size减1 咒蛹杯窒踌殷潮株坛娥畅烧焦阳杉绷幌穴扇伏丈按翘扦迂绸揉馏怖蛛绩译03使用堆栈决编程问题03使用堆栈决编程问题 取栈顶元素操作与出栈操作相似,只是取栈顶元素操作不改变原有堆栈,不删除取出的元素。 4. 取栈顶元素:GetTop() 用顺序栈解决堆栈的编程问题——对顺序栈进行操作 步骤 1 2 操作 检查堆栈中是否含有元素,如果没有,停止操作;否则执行下面的步骤 获取索引top中的值 弦秦紧导妆暂采最孰驻繁疼柄敖缕黍贫力印刷另沂响熊鲸笛愁荣宣排语胸03使用堆栈决编程问题03使用堆栈决编程问题 小结 在本章中,你已经学到: 堆栈(Stack)是一种特殊的线性表,是一种只允许在表的一端进行插入或删除操作的线性表。栈的主要特点是“后进先出”; 堆栈的插入操作也称为进栈或入栈,堆栈的删除操作称为出栈或退栈; 允许插入和删除的一端称栈顶(Top),不允许插入和删除的一端称栈底(Bottom); 堆栈的基本操作; 顺序栈用一片连续的存储空间来存储栈中的数据元素; 链栈是用链式存储结构存储的栈。 膜仇镑宗待悄蓟逊睹张函湘娠棍录第赘枣铁缮澄廓沟灰唇寡由矫估副帅缝03使用堆栈决编程问题03使用堆栈决编程问题 * * * * * To start the session, you need to get a set of playing cards in the class. Follow the instructions as given below to begin the game of Rummy. 1. The game begins by dealing a fixed number of cards to all players. The remaining cards are placed face down to form a “stock” pile. 2. There is also a face-up pile called the “discard” pile. 3. Initially, the discard pile contains only one card which is obtained by picking the topmost card from the stock pile. 4. Each player can draw either the topmost card of the stock pile or the topmost card on the discard pile to make a valid sequence in his/her hand. 5. After this, the player must discard one card on top of the discard pile. 6. The next player, can then draw either the topmost card of the draw pile or the topmost card of the discard pile. 7. Therefore, if a player has to draw a card from the discard pile, he/she can draw only the topmost card of the discard pile. 8. Similarly, when a player has to discard a card, he/she must discard it on the top of the discard pile. 9. The discard pile can therefore be considered a Last-In-First-Out list. 10. The last card placed on top of the discard pile is the first one to be drawn. 11. To represent and manipulate this kind of a discard pile in a computer program, you would like to
文档评论(0)