Skip to content

Instantly share code, notes, and snippets.

@zallarak
zallarak / linked_list_1.scm
Created January 9, 2012 00:38
Singly linked lists in Scheme (Lisp)
; 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)
@zallarak
zallarak / insertion_sort.rb
Created January 8, 2012 20:19
Insertion Sort (Ruby)
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
@zallarak
zallarak / insertion_sort.py
Created January 8, 2012 17:35
Insertion Sort
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