Reading, Deleting and Sorting Files Algorithms


Stack – Insertion

  1. Check to see if stack is full.

  2. If the stack is full report an error and stop.

  3. Increment the stack pointer.

  4. Insert new data item into cell pointed to by the stack pointer and stop.


Stack – Deletion/ Reading

  1. Check to see if the stack is empty.

  2. If the stack is empty report an error and stop.

  3. Copy data item in cell pointed to by the stack pointer.

  4. Decrement the stack pointer and stop.


Queues – Insertion

  1. Check to see if queue is full.

  2. If the queue is full report an error and stop.

  3. Insert new data item into cell pointed to by the head pointer.

  4. Increment the head pointer and stop.


Queues – Deletion/ Reading

  1. Check to see if the queue is empty.

  2. If the queue is empty report error and stop.

  3. Copy data item in cell pointed to by the tail pointer.

  4. Increment tail pointer and stop.


Trees – Insertion

  1. If tree is empty enter data item at root and stop.

  2. Current node = root.

  3. Repeat steps 4 and 5 until current node is null.

  4. If new data item is less than value at current node go left else go right.

  5. Current node = node reached (null if no node).

  6. Create new node and enter data.


Serial Search

1. If n < 1 then report error, array is empty.

2. For i = 1 to n do

a. If DataArray[i] = X then return i and stop.

3. Report error, X is not in the array and stop.


Binary Search

1. While the list is not empty do

a. Find the mid-point cell in the current list.

b. If the value in this cell is the required value, return the cell position and stop.

c. If the value to be found is less than the value in the mid-point cell then

Make the search list the first half of the current search list

Else make the search list the second half of the current search list.

2. Report error, item not in the list.