Zebra0.com

algorithms salt-pepperSalt and Pepper Pseudo code

Salt and Pepper Pseudo code

Pseudo code for swapping two values

In the illustration, the value of num1 is 5; the value of num2 is 12. We would like to swap num1 and num2 so that num1 is 12 and num2 is 5. We will use another variable, temp.

swap1

This is the algorithm for a classic swap. You will probably use this algorithm many times. Note that in an assignment statement, the variable that gets a new value is always on the left and the new value or expression is always on the right.

  1. temp=num1 step1
  2. num1=num2 step2
  3. num2=temp step2