insertion-sort

How can i perform an insertion sort but check a property of the element in the array not just the element?

Sorry, I'm sure this is simple but I'm tired and can't figure it out. I have an array of elements, each element is in fact a particle which is a data structure (a struct in c) containing, among other things the particles current position (int x,y,z). I want to compare the elements x position not just the element itself. Looking at the...

Inserting items in a list that is frequently insertion sorted

I have a list that is frequently insertion sorted. Is there a good position (other than the end) for adding to this list to minimize the work that the insertion sort has to do? ...

Insertion Sort Code Challenge

My task for you this time is to implement an insertion sort algorithm. Sure, everyone and his dog can do it; but how easy is it to do in the fewest characters? One must take an array (or suitable alternative in your language) of 32-bit integers and sort them by value via the insertion sort method, then return the sorted array as a copy ...

InsertionSort vs. InsertionSort vs. BinaryInsertionSort

I have a couple of questions concerning different implementations of insertion sort. Implementation 1: public static void insertionSort(int[] a) { for (int i = 1; i < a.length; ++i) { int key = a[i]; int j = i - 1; while (j >= 0 && a[j] > key) { a[j + 1] = a[j]; --j; } ...

Needed help understanding insertion sort

In this code how does this work (java): /** Move A[A.length-1] to the first position, k, in A such that there * are no smaller elements after it, moving all elements * A[k .. A.length-2] over to A[k+1 .. A.length-1]. */ static void moveOver (int A[]) { moveOver (A, A.length-1); } /** Move A[U] to the first position, k<=U, in A such...

Sort an array via x86 Assembly (embedded in C++)?? Possible??

I am playing around with x86 assembly for the first time and I can't figure out how to sort an array (via insertion sort).. I understand the algorithm, but assembly is confusing me as I primarily use Java & C++. Heres all I have so far int ascending_sort( char arrayOfLetters[], int arraySize ) { char temp; __asm{ push eax ...

Double Linked List Insertion Sorting Bug

Hello, I have implemented an insertion sort in a double link list (highest to lowest) from a file of 10,000 ints, and output to file in reverse order. To my knowledge I have implemented such a program, however I noticed in the ouput file, a single number is out of place. Every other number is in correct order. The number out of pla...

Java - Implementing sorting algorithms the 'right' way

I'm currently playing with implementing various sorting algorithms in Java, mostly for fun, but I'm struggling with how to do it 'right'. That is, I want the user to be able to call the sorting algorithm of choice on anything that is comparable - ints, longs, Strings, booleans (actually, are these comparable in Java?), their own classes;...

Insertion Sort on an array of strings in C#

If I have an array of strings, such as string[] names = {"John Doe", "Doe John", "Another Name", "Name Another"}; How do I sort this array, using insertion sort? Wikipedia has some examples: https://secure.wikimedia.org/wikibooks/en/wiki/Algorithm_implementation/Sorting/Insertion_sort#C.23 static void InsertSort(IComparable[] array)...