03使用堆栈解决编程问题.ppt

  1. 1、本文档共22页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
03使用堆栈解决编程问题

Pop操作就是从堆栈的顶部取出数据,即从链栈的起始处删除一个结点。要进行Pop操作,需要执行以下的步骤: 3. 出栈操作:T Pop( ) 用顺序栈解决堆栈的编程问题——对顺序栈进行操作 步骤 操作 1 检查堆栈中是否含有元素,如果没有,停止操作;否则执行下面的步骤 2 获取栈顶指示器top所指向结点的值 3 将栈顶指示器top指向单链表中下一个结点 4 栈元素个数size减1 取栈顶元素操作与出栈操作相似,只是取栈顶元素操作不改变原有堆栈,不删除取出的元素。 4. 取栈顶元素:GetTop() 用顺序栈解决堆栈的编程问题——对顺序栈进行操作 步骤 操作 1 检查堆栈中是否含有元素,如果没有,停止操作;否则执行下面的步骤 2 获取索引top中的值 小结 在本章中,你已经学到: 堆栈(Stack)是一种特殊的线性表,是一种只允许在表的一端进行插入或删除操作的线性表。栈的主要特点是“后进先出”; 堆栈的插入操作也称为进栈或入栈,堆栈的删除操作称为出栈或退栈; 允许插入和删除的一端称栈顶(Top),不允许插入和删除的一端称栈底(Bottom); 堆栈的基本操作; 顺序栈用一片连续的存储空间来存储栈中的数据元素; 链栈是用链式存储结构存储的栈。 * * * * * 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 use a list that: a. Contains the details of all the cards in the discard pile. b. Implements insertion and deletion of card details in such a way that the last i

文档评论(0)

yan698698 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档