Open main menu


Bubble SortEdit

Regular Bubble Sort
Language General Usage
Pseudocode
 1 n ← MaxIndex - 1
 2 FOR i ← 1 TO MaxIndex - 1
 3     FOR j ← 1 TO n
 4 		IF MyList[j] > MyList[j + 1]
 5 			THEN
 6 				Temp ← MyList[j]
 7 				MyList[j] ← MyList[j + 1]
 8 				MyList[j + 1] ← Temp
 9 		ENDIF
10 	ENDFOR
11 	n ← n - 1   // this means the next time round the inner loop, we don't
12 		        // look at the values already in the correct positions.
13 ENDFOR
VB.NET

Insertion SortEdit

Language General Usage
Pseudocode
1 FOR Pointer ← 2 TO NumberOfitems
2 	ItemToBeInserted ← List[Pointer]
3 	CurrentItem ← Pointer - 1 // pointer to last item in sorted part of list
4 	WHILE (List[CurrentItem] > ItemToBeInserted) AND (CurrentItem > 0)
5 		List[CurrentItem + 1] ← List[CurrentItem] // move current item down
6 		CurrentItem ← CurrentItem - 1 // look at the item above
7 	END WHILE
8 	List[CurrentItem + 1] ← ItemToBeInserted // insert item
9 ENDFOR
VB.NET