Professional Documents
Culture Documents
Stacks
Note that one danger in recursive programming is that the stack that
keeps return address and arguments could overflow if too many
recursive calls are made.
https://www.cs.usfca.edu/~galles/visualization/StackArray.html
There are three basic operations on a stack: push onto a stack, pop off
an element from a stack, and verify whether the stack is empty or not.
Here we will give pseudocode for stack operations.
a) push operation
Algorithm push(newElement)
b) pop operation
Algorithm pop()
elementToReturn = stack[topElementIndex]
topElementIndex topElementIndex - 1
return elementToReturn
c) isEmpty operation
Algorithm isEmpty()
if topElementIndex = -1
return true
else
return false
Queues
A queue works like a line at a movie theater: the first person to join
the rear of the line is the first person to reach to the front of the line to
buy a ticket. A queue is similar to a stack except in this behavior: the
first element added to it is the first element to be removed from it.
This is what is called as a fifo structure, first-in first-out.
https://www.cs.usfca.edu/~galles/visualization/QueueArray.html
There are two basic queue operations, insert and remove. Below is
the pseudocode for these basic operations. Note that in a queue data
structure two location identifiers (pointers) are kept: one for the
beginning of the queue and the other for the end of the queue. Having
two pointers makes both insertion and addition efficient. In the
pseudocode below the variable endOfQueueIndex will be used as the
pointer to the last element in a queue and beginningOfQueueIndex
will be used as the pointer to the first element in a queue.
a) insert operation
Algorithm insert(newElement)
b) remove operation
Algorithm remove()
elementToRemove = queue[beginningOfQueueIndex]
beginningOfQueueIndex beginningOfQueueIndex + 1
return elementToRemove
Linked-Lists
a) Algorithm insert(newElement)
b) Algorithm delete(element)
previousNode null
nextNode header
c) Algorithm find(element)
nextNode header
nextNode header