This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ; One may form pairs in Scheme with (cons ITEM1 ITEM2) | |
| ; For example, (cons 1 2) represents the pair 1 and 2 | |
| ; Let's define a the pair of 1 and 2 as one-and-two: | |
| (define one-and-two (cons 1 2)) | |
| ; Now one can invoke the pair with one-and-two | |
| ;1 ]=> one-and-two | |
| ; Value 11: (1 . 2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def InsertionSort(a) | |
| a.each_with_index do |item, index| | |
| i = index - 1 | |
| while i>=0 | |
| break if item >= a[i] | |
| a[i+1] = a[i] | |
| i -= 1 | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def InsertionSort(A): | |
| """ | |
| Takes a list, returns a list. | |
| """ | |
| for j in range(len(A)): | |
| key = A[j] | |
| i = j-1 | |
| while (i>=0) and (A[i]>key): | |
| A[i+1] = A[i] | |
| i = i-1 |
NewerOlder