VCE IT Lecture Notes by Mark Kelly, McKinnon Secondary College
Queues and Stacks |
||||||||||||||||
QueuesIt's common in computing to have a device or software module that has more work than it can handle - think of a class of 20 students all trying to print This is the process used by print queues to handle print jobs. It is also the system used by operating systems to handle events in the order in which they happen: if they got out of order, operations could be disastrous. For example, you click a text box to select it, then you type a few characters. If those events were handled in the wrong order, the typed text could be entered into whatever the active control was, leading to big, unpredictable problems. |
||||||||||||||||
StacksSee the theory slideshow! A stack is a simple yet powerful data structure that is used to store data to be used during computation. Stacks are fundamental to CPU processing Stacks obey a few primitive commands as simple as PUSH (to put data onto the top of the stack) and POP (retrieve data from the top of the stack and return it to the caller). Some stack implementations also allow commands like these: PEEP - retrieve a value from anywhere within the stack without removing it. DUP(licate) - push the value at the top of the stack onto the stack again. SWAP - swap the 2 values at the top of the stack ROTATE n - shift the first n stack items one place (so if a stack contained 1,2,3 then ROTATE 3 would change the stack to 2,3,1). ROTATE might come in flavours like left rotate and right rotate. Stacks can be easily implemented with a one-dimenstional array or a linked list and a simple stack pointer (a variable to keep track of the size of the stack). Stacks naturally form orderly queues. Stacks come in basic flavours:
A FILO stack in action:
|
||||||||||||||||
Implementing a stack in BasicDIM StackSize AS INTEGER 'global variable accessible to any subprogram SUB PUSH(value) FUNCTION POP( ) |
||||||||||||||||
Back to the IT Lecture Notes index
Back to the last page you visited
Created 14dec2010
Last changed: May 2, 2011 2:44 PM
VCE IT Lecture notes copyright © Mark Kelly 2001-