Sunday, March 17, 2019
Stacks :: Free Essay Writer
StacksData Structures and Algorithms 3.3 Stacks Another way of storing selective information is in a mound. A visual sense is generally implemented with solo two principle operations (apart from a constructor and destructor methods) pushadds an degree to a potpopextracts the most recently pushed feature from the stackOther methods such as trespassreturns the item at the masking without removing it 9isemptydetermines whether the stack has anything in it are sometimes added. A common pretence of a stack is a plate or coin stacker. Plates are pushed onto to the top and popped off the top. Stacks form Last-In-First-Out (LIFO) queues and have many applications from the parsing of algebraic expressions to ... A formal specification of a stack class would quality like typedef struct t_stack *stackstack ConsStack( int max_items, int item_size )/* Construct a new stack Pre-condition (max_items * 0) && (item_size * 0) Post-condition returns a pointer to an empty stack*/ repress Push( stack s, void *item )/* Push an item onto a stack Pre-condition (s is a stack created by a call to ConsStack) && (existing item count * max_items) && (item = NULL) Post-condition item has been added to the top of s*/void *Pop( stack s )/* Pop an item of a stack Pre-condition (s is a stack created by a call to ConsStack) && (existing item count *= 1) Post-condition top item has been removed from s*/Points to note a.A stack is simply another collection of data items and thus it would be possible to use exactly the same specification as the ace used for our general collection. However, collections with the LIFO semantics of stacks are so chief(prenominal) in computer science that it is appropriate to set up a limited specification appropriate to stacks only. b.Although a cerebrate key implementation of a stack is possible (adding and deleting from the head of a linked list produces exactly the LIFO semantics of a stack), the
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.