array sort

array sort

View Answers

July 27, 2009 at 1:04 PM

Hi Friend,

Try the following code:

public class SortArrayWithoutUsingMethod{
public static void sortArray(int array[], int len){
for (int i = 1; i < len; i++){
int j = i;
int tmp = array[i];
while ((j > 0) && (array[j-1] > tmp)){
array[j] = array[j-1];
j--;
}
array[j] = tmp;
}
}
public static void main(String a[]){
int i;
int array[]={7,2,9,6,4,8,3,1};
sortArray(array, array.length);
System.out.println("Sorted Array is: ");
for(i = 0; i <array.length; i++){
System.out.println(array[i]);
}
}

}

Thanks









Related Tutorials/Questions & Answers:
Array sort
Array sort  Program that uses a function to sort an array of integers
php array sort by field
php array sort by field  Array sort by field in PHP
Advertisements
php array sort by key
php array sort by key  php script to sort array by key
php array sort by value
php array sort by value  an example to sort the array by value
php array sort functions
php array sort functions  Sort function in php
string array sort
string array sort  Hi. How to sort a string array
string array sort
string array sort  Hi. How to sort a string array
string array sort
string array sort  Hi. How to sort a string array
string array sort
string array sort  Hi. How to sort a string array
string array sort
string array sort  Hi. How to sort a string array
array sort - Java Beginners
array sort  hi all, can anybody tell me how to sort an array... array[], int len){ for (int i = 1; i < len; i++){ int j = i; int tmp = array[i]; while ((j > 0) && (array[j-1] > tmp
php array sort
PHP Array sort function is used to sort the given array in ascending order. Example of PHP Array Sort <?php $ar1=array("jack","mac","rock","barak");ADS_TO_REPLACE_1 sort($ar1); foreach ($ar1 as $a) echo " ".$a;ADS
PHP Array Sort in Reverse Order
PHP Array Sort in Reverse Order  Hi, I have just started learning... the PHP Array Sort in Reverse Order. Please suggest any online reference or example... programming language there are three types of functions used to sort the array
Merge Sort String Array in Java
Merge Sort String Array in Java  Hello, I am trying to implement a merge sort algorithm that sorts an array of Strings. I have seen numerous.... Note: I have a separate class for merge sort in which i pass my list and the size
String array sort
String array sort  Hi here is my code. If i run this code I am getting exception as java.lang.NllPointerException. I think its because of at the line... for loop is to remove the null from the source array*/ for(int i=0;i<
String array sort
String array sort  Hi here is my code. If i run this code I am getting exception as java.lang.NllPointerException. I think its because of at the line... for loop is to remove the null from the source array*/ for(int i=0;i<
JavaScript array sort alphabetically
JavaScript array sort alphabetically       We can sort the JavaScript array elements by using the sort() method of Array class in JavaScript. Syntax of the sort method
Java insertion sort with string array
Java insertion sort with string array In this tutorial, you will learn how to sort array of strings using string array with Insertion Sort. For this, we... array using inserting sort algorithm. In the main method, we have  invoked
JavaScript array sort numerically
JavaScript array sort numerically   ... alphabetically we have used the default sort method to sort array elements but here... array sort() numerically </title> <script type="text/javascript">
C array sort example
C array sort example       In this section, you will learn how to sort an array in C. For sorting...;i;   qsort(array, 10, sizeof(int), sort);   
PHP Sort Array
PHP Sort Array: Sometimes we need to store data in a single entity called... array, how to sort values of an array, and how to sort the keys... to know how to use array in PHP. PHP Sort Array Example: <?phpADS
JavaScript array functions sort
JavaScript array functions sort   ... to understand the concept of JavaScript array function sort. The code create... to array. The function show( )  include array. sort( ) method. array. sort
please please i wanna insertion sort program find calendar to array value (1000,5000,10000), please help me
Insertion sort program find calendar to array value 1000,5000,10000  program find calendar for insertion sort in jfram to array 1000
Insertion Sort In Java
after the sort: 1 3 4 9 10 12 99 120 PAUSE C:\array... Insertion Sort In Java     ... In this example we are going to sort integer values of an array using insertion sort
Selection Sort In Java
same steps. Working of the selection sort :Say we have an array... Selection Sort In Java      ... are going to sort the values of an array  using selection sort.In selection sorting
Heap Sort in Java
Heap Sort in Java is used to sort integer values of an array. Like quicksort, insertion sort, bubble sort and other sorting methods, heap sort is used...:\array\sorting>java heap_Sort Heap Sort --------------- Unsorted Array 1 3
Merge Sort In Java
are followed by merge sort algorithm to sort the values of an array. Step1:Spliting.... Steps of Merge Sort: Say unsorted  an array values... Merge Sort in Java      
Quick Sort In Java
: In quick sort algorithm pick an element from array... Quick Sort in Java      ... to sort integer values of an array using quick sort. Quick sort algorithm
Selection Sort in Java
Selection sort in Java is used to sort the unsorted values in an array. In selection sorting algorithm, the minimum value in an array is swapped to the very first position in that array. In the next step the first value of array
Sort
Sort  program to sort a list of numbers in decendimg order   Hi Friend, Try the following code:ADS_TO_REPLACE_1 import java.util.*; class SortListInDescendingOrder{ public static void main(String[] args
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, insertion sort, selection sort, etc... mergeSort.java C:\array\sorting>java mergeSort RoseIndia Selection Sort Values
Quick Sort in Java
Quick sort in Java is used to sort integer values of an array... into a sorted array. ADS_TO_REPLACE_1 Example of Quick Sort in Java: public class... the sort:\n"); for(i = 0; i < array.length; i++) System.out.print( array
Bidirectional Bubble Sort in Java
-directional bubble sort algorithm to sort the values of an array.  ... Bidirectional Bubble Sort in Java       Introduction : Bidirectional Bubble Sort
Quick Sort in Java
Quick Sort in Java Quick Sort in Java is used to sort elements of an array. Quick sort works on divide and conquer strategy and comparison sort..., insertion sort, heap sort and other sorting algorithms. First it divides an array
Odd Even Transposition Sort In Java
Odd Even Transposition Sort In Java   ... In this example we are going to sort integer values of an array using odd even transposition sort. Odd even transposition sort is a parallel sorting algorithm. Odd Even
Extra Storage Merge Sort in Java
into an array .Then again merge the next part , sort it and store into an array. Do... sort the sorted values are stored in an other array. Working of extra storage merge sort algorithm: Say we have an array unsorted 
Finding an Element in a Sorted Array
. In this section, you will learn how to sort an array and how to find a text in the sorted array. For binary search first you must sort the array and then apply the binary... Finding an Element in a Sorted Array   
PHP Array Reverse Sorting
PHP Array Sort in Reverse Order In PHP there are three functions are available...() is one of them, it sorts an array in reverse order, rsort() is just opposite sort() function: General Format bool rsort(array $array [,int $sort
PHP Array Sorting
Array Sort To sort an array we need to use sort() function. Small description... bool sort(array $array [,int $sort_flags=SORT_REGULAR... Parameters array: the input array sort_flags
quick sort
the sort:\n"); for(i = 0; i < array.length; i++){ array[i... answer "array based problem" for run time input.but i am facing some problem.plz... static void quick_srt(int array[],int low, int n){ int lo = low; int hi
quick sort
the sort:\n"); for(i = 0; i < array.length; i++){ array[i... answer "array based problem" for run time input.but i am facing some problem.plz... static void quick_srt(int array[],int low, int n){ int lo = low; int hi
quick sort
the sort:\n"); for(i = 0; i < array.length; i++){ array[i... answer "array based problem" for run time input.but i am facing some problem.plz... static void quick_srt(int array[],int low, int n){ int lo = low; int hi
array string
array string  how to sort strings with out using any functions
in_array
in_array  in_array in php
is _array()
is _array()  is_array() in php   Hi Friend, This function is of Boolean type.It checks whether a variable is an array or not. Here is an example: <?php $yes = array('Hello', 'World'); echo is_array($yes) ? 'Array
is _array()
is _array()  is _array()   Hi Friend, This function is of Boolean type.It checks whether a variable is an array or not. Here is an example: <?php $yes = array('Hello', 'World'); echo is_array($yes) ? 'Array
Heap Sort in Java
minimum root than his child. We can sort the array values using heap sorting...;Javac heap_Sort.java C:\array\sorting>java heap_Sort Heap Sort --------------- Unsorted Array 1 3
Array
Array  how can i use elements of an array in a circular form? that is if the searching of the element reach the last elements of the array, then it will start serching from the begining of the array
Array
Array  is it possible to define array like this..? int[] intArray = new int[] {4,5,6,7,8}; Explain...?   Yes, you can. Java Initialize Array
bubble sort - Java Beginners
bubble sort  how to write program The bubble-sort algorithm in double...  Hi friend, Bubble Sort program : public class BubbleSortExam{ public static void main(String a[]){ int i; int array

Ads