Thursday, December 6, 2007

Stack

The stack implementation is a lot simpler than the queue, as only the pointer to the last element is needed. In this case, we use the entry: 'next', which points to the location where the next 'push' to the stack should place the element to. The following diagrams illustrate the operations performed on a stack. The example shows two 'push' operations to the stack, and followed by a 'pop' at the end.

Stack empty and initialized:
Statement: stack_init (my_stack);

3
2
1
0 <- next +---+ Stack with 1 element 'push'ed Statement: stack_push (my_stack, "a"); 3 2 1 <- next 0 a +---+ Stack with 1 more element 'push'ed Statement: stack_push (my_stack, "b"); 3 2 <- next 1 b 0 a +---+ Stack after a 'pop' function call: Statement: stack_pop (my_stack, myval); # myval will contain "b" 3 2 1 <- next 0 a +---+


Stack

stack_init
Initializes a stack. The stack will be cleared of all its existing entries.
stack_length
Returns the length of the stack.
stack_push
Adds an entry to the end of the stack.
stack_pop
Remove an entry from the end of the stack.
stack_isempty
Whether the stack is empty.

In programming, a special type of data structure in which items are removed in the reverse order from that in which they are added, so the most recently added item is the first one removed. This is also called last-in, first-out (LIFO). Adding an item to a stack is called pushing. Removing an item from a stack is called popping.
A set of network protocol layers that work together. The OSI Reference Model that defines seven protocol layers is often called a stack, as is the set of TCP/IP protocols that define communication over the internet. The term stack also refers to the actual software that processes the protocols. So, for example, programmers sometimes talk about loading a stack, which means to load the software required to use a specific set of protocols. Another common phrase is binding a stack, which refers to linking a set of network protocols to a network interface card (NIC). Every NIC must have at least one stack bound to it. In Windows, the TCP/IP stack is implemented by the Winsock DLL.


No comments: