what is the best way to get O(n) memory usage in insertion sort?
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
what is the best way to get O(n) memory usage in insertion sort?
Last edited by lovon; October 2nd, 2011 at 06:10 AM.
See Insertion sort - Wikipedia, the free encyclopedia
If you are still confused, please post a more specific question about what you are confused about.
Hi!!!!
This is insertion sort algorithm
public class insertSort {
public static void main(String[] args) {
int[] array={3,4,5,6,7,8,1,2,3};
int temp;
for(int i=0;i<array.length;i++)
for(int j=i;j>0;j--)
if(array[j]>array[j-1]){
temp=array[j];
array[j]=array[j-1];
array[j-1]=temp;
}
for(int i=0;i<array.length;i++)
System.out.print(array[i]+" ");
System.out.println();
}
}
Think how here to implement data Structures.
Hope this helps