Just another update

This commit is contained in:
Ingy döt Net 2015-02-20 00:35:01 -05:00
parent a25938f123
commit 00a190b0a6
6591 changed files with 94363 additions and 23227 deletions

View file

@ -1,5 +1,7 @@
{{data structure}}[[Category:Classic CS problems and programs]]
A '''stack''' is a container of elements with last in, first out access policy. Sometimes it also called '''LIFO'''. The stack is accessed through its '''top'''. The basic stack operations are:
A '''stack''' is a container of elements with last in, first out access policy.
Sometimes it also called '''LIFO'''. The stack is accessed through its '''top'''.
The basic stack operations are:
* ''push'' stores a new element onto the stack top;
* ''pop'' returns the last pushed stack element, while removing it from the stack;
@ -9,7 +11,12 @@ Sometimes the last pushed stack element is made accessible for immutable access
* ''top'' (sometimes called ''peek'' to keep with the ''p'' theme) returns the topmost element without modifying the stack.
Stacks allow a very simple hardware implementation. They are common in almost all processors. In programming stacks are also very popular for their way ('''LIFO''') of resource management, usually memory. Nested scopes of language objects are naturally implemented by a stack (sometimes by multiple stacks). This is a classical way to implement local variables of a reentrant or recursive subprogram. Stacks are also used to describe a formal computational framework. See [[wp:Stack_automaton|stack machine]]. Many algorithms in pattern matching, compiler construction (e.g. [[wp:Recursive_descent|recursive descent parsers]]), and machine learning (e.g. based on [[wp:Tree_traversal|tree traversal]]) have a natural representation in terms of stacks.
Stacks allow a very simple hardware implementation.
They are common in almost all processors. In programming stacks are also very popular for their way ('''LIFO''') of resource management, usually memory.
Nested scopes of language objects are naturally implemented by a stack (sometimes by multiple stacks).
This is a classical way to implement local variables of a reentrant or recursive subprogram. Stacks are also used to describe a formal computational framework.
See [[wp:Stack_automaton|stack machine]].
Many algorithms in pattern matching, compiler construction (e.g. [[wp:Recursive_descent|recursive descent parsers]]), and machine learning (e.g. based on [[wp:Tree_traversal|tree traversal]]) have a natural representation in terms of stacks.
Create a stack supporting the basic operations: push, pop, empty.

View file

@ -15,7 +15,3 @@ check_foo! :
{foo empty?) {nil} {"not " .} ifte
"empty" .
cr << }
Output:
foo is not empty
foo is empty

View file

@ -4,5 +4,5 @@ function Stack() {
this.push = function(element) {this.data.push(element)}
this.pop = function() {return this.data.pop()}
this.empty = function() {return this.data.length == 0}
this.peek = function() {return this.data[0]}
this.peek = function() {return this.data[this.data.length - 1]}
}

View file

@ -0,0 +1,24 @@
function makeStack() {
var stack = [];
var popStack = function () {
return stack.pop();
};
var pushStack = function () {
return stack.push.apply(stack, arguments);
};
var isEmpty = function () {
return stack.length === 0;
};
var peekStack = function () {
return stack[stack.length-1];
};
return {
pop: popStack,
push: pushStack,
isEmpty: isEmpty,
peek: peekStack,
top: peekStack
};
}

View file

@ -0,0 +1,6 @@
s := Stack new.
s push: 1.
s push: 2.
s push: 3.
s pop.
s top. "2"