| Line 4: |
Line 4: |
| | The counter variables in this pseudocode are 0-based. | | The counter variables in this pseudocode are 0-based. |
| | | | |
| − | '''for''' x = 1 to len(Vals[]) //start at the second value (because the first one is already "sorted")
| + | '''for''' x = 1 to len(Vals[]) //start at the second value (because the first one is already "sorted") |
| − | nextval = Vals(x) //retrieve the next value from the series
| + | nextval = Vals(x) //retrieve the next value from the series |
| − | y = x - 1 //create a counter variable to store the position of the next value to be compared
| + | y = x - 1 //create a counter variable to store the position of the next value to be compared |
| − | '''while''' y > -1 '''and''' Vals(x) > nextval //go through all the values to left and compare, the inequality sign will
| + | '''while''' y > -1 '''and''' Vals(x) > nextval //go through all the values to left and compare, the inequality sign will |
| − | //vary based upon the sorting type (nondecreasing or nonincreasing)
| + | //vary based upon the sorting type (nondecreasing or nonincreasing) |
| − | Vals(y + 1) = Vals(x) //compare the value to the left because the conditions haven't been met yet
| + | Vals(y + 1) = Vals(x) //compare the value to the left because the conditions haven't been met yet |
| − | y-- //decrease the counter
| + | y-- //decrease the counter |
| − | Vals(y + 1) = nextval //store the value in the right position
| + | Vals(y + 1) = nextval //store the value in the right position |
| | | | |
| | | | |
| | [[Category:Computer Science]] | | [[Category:Computer Science]] |