Plain text

Red Text

@

Code

Algorithm InsertionSort(dataList)
// dataList is a zero-indexed list/array of sortable data
// n is the length of dataList
// algorithm modifies the dataList; returns the modified list
for i = 1 to n-1 do
	let j = i
	while j > 0 and dataList[j] < dataList[j-1] do
		swap dataList[j] and dataList[j-1]
		let j = j - 1
return dataList