Wednesday, May 29, 2019
Stacks :: Free Essay Writer
StacksData Structures and Algorithms 3.3 Stacks Another way of storing data is in a big bucks. A muckle is superior generally implemented with only two principle operations (apart from a constructor and destructor methods) pushadds an item to a stackpopextracts the most recently pushed item from the stackOther methods such as topreturns the item at the top without removing it 9isemptydetermines whether the stack has anything in itargon sometimes added. A common model of a stack is a plate or coin stacker. Plates are pushed onto to the top and popped off the top. Stacks stratum 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 look 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*/void 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 one used for our general collection. However, collections with the LIFO semantics of stacks are so important in computer science that it is usurp to set up a limited specification appropriate to stacks only. b.Although a linked list 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.