I wana run a JUnit test on Eclipse Helios Editor..I dont need a main()method in the program for that...could any1 pls post the Test case code snippet for me?Cant seem to be able to figure it out :-(
Additional question -- what is the other way without initializing the Array... that the user can input any numbers he/she want? Ex. he input 5 integer: 5 3 2 4 1...
I don't know who wrote the above code, but its pretty bad. I've been programming java for only 2 years and have fixed this code up. why does insertion_srt() need a parameter for the length of the array? the method can just use array.length.
I dont normally comment on things like this, but this code was soo bad i had to. please fix it up so future users are not confused by the useless complexity of the code
The code and output says 'Selection Sort' though the program is for 'Insertion Sort'.
Thanks for this article, really helped me learning this messed-up sorting.
QuestionAlexander Baggett December 12, 2012 at 3:52 AM
What does n represent in this example?
Java programsMukul Kantiwal November 12, 2012 at 11:07 AM
There is a problem...Francis July 9, 2011 at 4:05 PM
I think the code is not insertion sort!!! @_@
computingMayank aka Flash October 8, 2011 at 5:18 PM
beter and simple! [code] import java.io.*; class insertion { public static void main() throws IOException { InputStreamReader isr = new InputStreamReader(System.in); BufferedReader br= new BufferedReader(isr); System.out.println("Please Enter the number of values"); int a=Integer.parseInt(br.readLine()); int age[]=new int[a]; int minelem=0, temp; System.out.println("Enter the VALUES"); for(int x=0;x<a;x++) { age[x]=Integer.parseInt(br.readLine()); } System.out.println("The number in ascending order are: "); int min; for(int x=0;x<a-1;x++) { min=age[x]; for(int y=x+1;y<a;y++) { if(min>age[y]) { min=age[y]; minelem=y; } } System.out.println("Minimum Value: " + min); temp=age[minelem]; age[minelem] = age[x]; age[x]=temp; } for(int w=0;w<a;w++) { System.out.println(age[w]); } } } [/code]
does this also work with a linked listjoel November 7, 2011 at 9:57 PM
does this code example work with a linked list for inserting a linked list.
InsertSortManohar Reddy November 16, 2011 at 12:13 PM
package com.manohar.sort; public class InsertionSort { /** * @param args */ public static void main(String[] args) { int a[] = { 6, 3, 1,9,4,3,5,8,1,6 }; int temp; for (int i = 0; i < a.length; i++) { int j = i + 1; while (j < a.length && j>0 && a[j] < a[j - 1]) { temp = a[j]; a[j] = a[j - 1]; a[j - 1] = temp; j--; } } for (int i = 0; i < a.length; i++) { System.out.print("->" + a[i]); } } }
Very nice..vaengai December 2, 2011 at 1:16 PM
Very nice..
binuangMichael January 14, 2013 at 12:08 PM
your teaching is not yet good!!!
Did not understandNeo January 16, 2012 at 2:56 PM
I wana run a JUnit test on Eclipse Helios Editor..I dont need a main()method in the program for that...could any1 pls post the Test case code snippet for me?Cant seem to be able to figure it out :-(
ThisJohn March 2, 2012 at 7:31 PM
In the output, you say it's selection sort, but it's insertion sort. Just a heads up
Computer Scienceochi March 12, 2012 at 1:39 PM
SUPERB EXAMPLE!!
Insertion SortPaul April 3, 2012 at 11:14 AM
Hi Rose! I would to ask about this Insertion Sort if this is a (doubly linked list)? I hope you will reply early... thanks
Insertion SortPaul April 3, 2012 at 2:03 PM
Additional question -- what is the other way without initializing the Array... that the user can input any numbers he/she want? Ex. he input 5 integer: 5 3 2 4 1...
activity selectionfateme April 20, 2012 at 6:27 PM
activity selectoin algorith with all improved soulotion
This CodeAndy June 27, 2012 at 7:49 AM
I don't know who wrote the above code, but its pretty bad. I've been programming java for only 2 years and have fixed this code up. why does insertion_srt() need a parameter for the length of the array? the method can just use array.length. I dont normally comment on things like this, but this code was soo bad i had to. please fix it up so future users are not confused by the useless complexity of the code
selection sortnjaks August 15, 2012 at 9:35 PM
write a driver class to contain the following 1.method to input 10 numbers 2.sort the 10 numbers in ascending order. 3.display the sorted numbers
goodkiran August 21, 2012 at 10:59 AM
The way of illustrating is good ....PLz could you suggest more about java languages to
BAD CODEbig1burrito December 7, 2012 at 8:46 AM
you did your swap wrong. use a temp variable to move value of array[j] to array[j-1]
TypoSiddharth December 8, 2012 at 1:24 PM
The code and output says 'Selection Sort' though the program is for 'Insertion Sort'. Thanks for this article, really helped me learning this messed-up sorting.
QuestionAlexander Baggett December 12, 2012 at 3:52 AM
What does n represent in this example?
Java programsMukul Kantiwal November 12, 2012 at 11:07 AM
I need a program for insertion sort
Post your Comment