I am creating a pseudocode in determining the smallest and largest number among 3 numbers:
My code is as follows:
If (x >= y)
largest = x
Smallest = y
Else
largest = y
Smallest =x
If (z >= largest)
Largest = z
If (z <= smallest)
Smallest = z
Do you think this is correct? or are there better ways to solve this?
Let’s say you’ve got arbitrary numbers
x, y, z.Pseudocode:
This is one way to solve your problem if you’re using only variables, assignment, if-else and comparison.
If you have arrays and a sort operation defined over it, you can use this:
If you have a
maxandminfunction that takes an array of numbers as an argument, you can use this:If you also have positional assignment using sets, you can use this:
If you have a data structure that will sort it’s contents when inserting elements, you can use this: