Data Bases
Custom Term Papers
Free Term Papers
Free Research Papers
Free Essays
Free Book Reports
Plagiarism?
Links
Top 100 Term Paper Sites
Top 25 Essay Sites
Top 50 Essay Sites
Search 97,000 Papers @ DirectEssays.com
Search 101,000 Papers @ ExampleEssays.com
Search 90,000 Papers @ MegaEssays.com
Free Essays
Term Paper Sites
Chuck III's Free Essays
Free College Essays
TermPaperSites.com
My Term Papers
Get Free Essays
Essay World
Planet Papers
Search Lots of Essays
Back to Subjects
-
Computers
stacks
stacks Another way of storing data is in a stack. A stack is generally implemented with only two principle operations (apart from a constructor and destructor methods): pop extracts the most recently pushed item from the stack top returns the item at the top without removing it [9] isempty determines whether the stack has anything in it 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 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 look like: stack ConsStack( int max_items, int item_size ); Pre-condition: (max_items * 0) && (item_size * 0) Post-condition: returns a pointer to an empty stack Pre-condition: (s is a stack created by a call to ConsStack) && (existing item count * max_items) && Post-condition: item has been added to the top of s Pre-condition: (s is a stack created by a call to (existing item count *= 1) Post-condition: top item has been removed from s 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 appropriate 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 most common applications for stacks have a space restraint so that using an array implementation is a natural and efficient one (In most operating systems, allocation and de-allocation of memory is a relatively expensive operation, there is a penalty for the flexibility of linked list implementations.). Almost invariably, programs compiled from modern high level languages (even C!) make use of a stack frame for the working memory of each procedure or function invocation. When any procedure or function is called, a number of words - the stack frame - is pushed onto a program stack. When the procedure or function returns, this frame of data is popped off the stack. As a function calls another function, first its arguments, then the return address and finally space for local variables is pushed onto the stack. Since each function runs in its own "environment" or context, it becomes possible for a function to call itself - a technique known as recursion. This capability is extremely useful and extensively used - because many problems are elegantly specified or solved in a recursive way. Program stack after executing a pair of mutually recursive functions: function f(int x, int y) { int a; if ( term_cond ) return ...; a = .....; return g(a); }function g(int z) { int p,q; p = ...; q = ...; return f(p,q); }Note how all of function f and g's environment (their parameters and local variables) are found in the stack frame. When f is called a second time from g, a new frame for the second invocation of f is created. Generic terms for adding something to, or removing something from a stack The environment in which a function executes: includes argument values, local variables and global variables. All the context except the global variables is stored in a stack frame. The data structure containing all the data (arguments, local variables, return address, etc) needed each time a procedure or function is called. Bibliography:
Word Count: 670
Copyright © 1998-2008
College Term Papers
, INC All Rights Reserved.
DMCA Notifications and Requests