Last active
January 2, 2017 03:30
-
-
Save SanjeevMohindra/9c2f470657da39556998772f7b506835 to your computer and use it in GitHub Desktop.
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
| func insertionSort(inputData: inout [Int]) { | |
| for forwardPointer in 1...inputData.count - 1 { | |
| let selectElement = inputData[forwardPointer] //Select the element | |
| var reversePointer = forwardPointer - 1 //Set the reverse pointer | |
| while (reversePointer >= 0 && selectElement < inputData[reversePointer]) { | |
| inputData[reversePointer + 1] = inputData[reversePointer] //move the value forward | |
| reversePointer -= 1; //decrease the pointer | |
| } | |
| inputData[reversePointer + 1] = selectElement //store the value at correct place | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment