Sunday, September 26, 2010

is sorted

1.Create list of numbers(ex. 5, 4, 1, 6)
2.If 5(first number on the left) is smallest number, change none. Then go to step 8.
3.But if 5 isn't smallest number in list, then compare 5 with 4(second number) for find smaller number
4.5 is larger than 4, then change position 5 with 4(4, 5, 1, 6).
5.And compare 4 with 1(third number). 1 is larger than 4. So change 4 with 1(1, 5, 4, 6)
6.Then compare 1 with 6(fourth number). 1 is smaller than 6, then change none.
7.We compare all of numbers then knew 1 is smallest number.
8.If we found smallest number, left that number and find next smallest number.
8.Repeat step 2~8.
9.It end when we repeat step 2~8 n(numbers in the list of numbers)-1 times.




 This is work for any numbers because it just compare n number with the next number in the list then repeats it to find the order of numbers. And this is in finite time because we need to repeats just  n-1 times.

No comments:

Post a Comment