Insertion Sort 1 Answer(s) 2 years and 11 months ago
Posted in : Java Beginners
Hello rose india java experts.If you don't mind.Can you help me.What is the code for Insertion Sort and Selection Sort that displays LETTERS in alphabetical order from A to Z.
Thank you.Hope you gonna helpme.
View Answers
July 5, 2010 at 5:38 PM
Hi Friend,
Try the following code:
1)InsertionSort.java:
public class InsertionSort { public static void sort(String[] array) { int N = array.length; for (int i = 1; i < N; i++) for (int j = i; j > 0; j--) if (array[j-1].compareTo(array[j]) > 0) change(array, j, j-1); else break; } private static void change(Comparable[] a, int i, int j) { Comparable swap = a[i]; a[i] = a[j]; a[j] = swap; } public static void main(String[] args) { String[] array ={"S","D", "A","B","Z", "M","O", "L","H", "Y"}; sort(array); for (int i = 0; i < array.length; i++) { System.out.print(array[i] + " "); } System.out.println(); } }
2)SelectionSOrt.java:
import java.util.*;
public class SelectionSort{ public static void main(String a[]){ String array[] = {"S","D", "A","B","Z", "M","O", "L","H", "Y"}; sort(array, array.length);
System.out.println("Data items in ascending order"); for(int i = 0; i <array.length; i++) System.out.print(array[i]+" "); } public static void sort(String array[], int n) { for (int x = 0; x < n; x++) { int min = x; for (int y = x; y < n; y++) { if (array[min].compareTo(array[y]) > 0) { min = y; } } String temp = array[x]; array[x] = array[min]; array[min] = temp; } } }
Hope that it will be helpful for you. Thanks
Related Pages:
insertion sort insertion sort write a program in java using insertionsort
insertion sort insertion sort write a program in java using insertionsort
insertion sort insertion sort write a program in java using insertionsort
insertion sort insertion sort write a program in java using insertionsort
insertion sort insertion sort how many arrays needed for insertionsort and why
Insertion Sort Applet InsertionSort Applet Please All , I need Insertionsort applet program
Insertion Sort Applet InsertionSort Applet I need InsertionSort Applet code was design by Dr. Daniel Liang
Please
Insertion Sort Timer InsertionSort Timer Welcome all
I wanna program in java find the timer of insertionsort and find time complexity for random value
thanks all
Java insertion sort question
Java insertionsort question I've got another program that I need help with. I am trying to write a Java method that accepts an array of strings, and sorts the strings using the insertionsort algorithm. Then I need to write
Insertion Sort Problem InsertionSort Problem So I have this in a class file. It is supposed to be an insertion sorter:
int min, index=0, temp;
for(int i=0;i<sorted.length;i++){
min=sorted[i];
for(int j=i+1;j<
Insertion Sort - Java Beginners Insertion Sort Hello rose india java experts.If you don't mind.Can you help me.What is the code for InsertionSort and Selection Sort that displays...:
public class InsertionSort {
public static void sort(String[] array) {
int
Insertion Sort In Java InsertionSort In Java
 ... to sort integer values of an array using
insertionsort.
Insertion sorting algorithm is similar to bubble sort. But insertionsort is
more 
Insertion Sort Java InsertionSort in Java is an algorithm that is used to sort integer values..., InsertionSort in Java is less efficient when it comes to larger data sets... decreasing.
How does InsertionSort works in Java?
Assume that you have 5
Java insertion sort with string array
Java insertionsort with string array
In this tutorial, you will learn how to sort array of strings using string
array with InsertionSort. For this, we... array using inserting sort algorithm. In the main method, we
have invoked
complete this code (insertion sort) - Java Beginners
complete this code (insertionsort) Your task is to develop part... to use a modiŻed version of insertion-sort algorithm
which works as follows... to sort */
Scanner sc; /* for reading user input */
String line
Heap Sort in Java
Heap Sort in Java is used to sort integer values of an array. Like quicksort,
insertionsort, bubble sort and other sorting methods, heap sort is used to sort
an unsorted list. When compared to other sorting methods heap sort
Merge Sort Java
Merge Sort in Java is used to sort integer values of an array. There are many
methods to sort Java like bubble sort, insertionsort, selection sort, etc. In
Merge sort unsorted values are divided into two equal parts
Quick Sort in Java
Quick sort in Java is used to sort integer values of an array. It is a
comparison sort. Quick sort is one of the fastest and simplest sorting algorithm
in comparison to other sorting algorithms like bubble sort, insertionsort, heap
Sort
Sort program to sort a list of numbers in decendimg order
Hi Friend,
Try the following code:
import java.util.*;
class SortListInDescendingOrder{
public static void main(String[] args
Insertion into database Insertion into database Hi,
I need code for inserting the multiple select box values into database.Please do send me the code.
Thanks for ur immediate replies its helping a lot
Insertion, sorting and searching in array
;
}
Insertion, sorting and searching in array
 ... declare an array of
integer type and then sort by using java.util.Arrays.Sort...("Elements in array", array);
// sort then print the specified arrray
hibernate insertion problem - Hibernate
hibernate insertion problem Hi ,
Thanks for the material .Its very gud .
when i run FirstExample.java i get the message insertion has been done int the table contact . but whne i look into database data is not inserted
Array sort
Array sort Program that uses a function to sort an array of integers
bubble sort
bubble sort write a program in java using bubble sort
bubble sort
bubble sort how to calculate the number of passes in bubble sort
insertion in SQL - SQL insertion in SQL Hi!
Everybody... i have a problem with sql insertion.
When i am inserting values through command i.e.
insert into employee values(,,,,);
here i want to insert ' in employee name column of database
buble sort
buble sort ascending order by using Bubble sort programm
Java BubbleSort Example
SEARCH AND SORT
SEARCH AND SORT Cam any one provide me the code in java that :
Program to search for MAX,MIN and then SORT the set using any of the Divide and conquer method
insertion error - JSP-Servlet insertion error my first jsp page :
In this i m getting all the values through a method called getAllDetails,the values are getting inserted but the problem is i have created frames , when i clicking on the link book halls
insertion in SQL - SQL insertion in SQL Query is "insert into employee values('"+eno+"','"+ename+"');"
in the ename place we will get employee names such as
John's Peter,Peter's Johnson etc....
i am not able to insert this kind of names
dynamic delete and insertion in tables
dynamic delete and insertion in tables hey... i have a problem..I am working on a problem management system..my code for a particular jsp page is as follows in this page i want to show the admin the already present records
data insertion and fetch 1
data insertion and fetch 1 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
<%@page contentType="text/html" pageEncoding="UTF-8"%>
Location
Fill Up Your Details
<center> <form action
dynamic delete and insertion in tables
dynamic delete and insertion in tables hey... i have a problem..I am working on a problem management system..my code for a particular jsp page is as follows in this page i want to show the admin the already present records
quick sort
;
System.out.println(" Quick Sort\n\n");
System.out.println("Values Before the sort:\n");
for(i = 0; i < array.length; i++){
array[i...("Values after the sort:\n");
for(i = 0; i <array.length; i
quick sort
;
System.out.println(" Quick Sort\n\n");
System.out.println("Values Before the sort:\n");
for(i = 0; i < array.length; i++){
array[i...("Values after the sort:\n");
for(i = 0; i <array.length; i
quick sort
;
System.out.println(" Quick Sort\n\n");
System.out.println("Values Before the sort:\n");
for(i = 0; i < array.length; i++){
array[i...("Values after the sort:\n");
for(i = 0; i <array.length; i
Inserting content(DOM Insertion)
Inserting content(DOM Insertion)
Inserting content(DOM Insertion)
Inserting... :
DOM insertion
DOM insertion, Around
DOM
Binary search tree (insertion) urgent!!
Binary search tree (insertion) urgent!! Create a program to construct a binary search tree consisting of nodes that each stores
an integer in Java.Avoid duplication of values when inserting nodes in the tree. When a new leaf