Created
October 30, 2015 16:19
-
-
Save edinak1/9ba550d93691755d1e3d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package masiv; | |
import java.util.Arrays; | |
public class Sort { | |
public static void main(String[] args) { | |
int[] data=new int[10000]; | |
for(int i=0,k=10000;i<10000;i++,k--) | |
data[i]=k; | |
System.out.println(Arrays.toString(data)); | |
System.out.println("Time for sort array data[10000]"); | |
sort(data); | |
System.out.println("Array is sort:"); | |
System.out.println(Arrays.toString(data)); | |
} | |
static void swap(int[]data,int k) | |
{ | |
for(int i=0,temp; i<data.length-k; i++) | |
{ | |
if(data[i]>data[i+1]) | |
{ | |
temp=data[i]; | |
data[i]=data[i+1]; | |
data[i+1]=temp; | |
} | |
} | |
} | |
static void sort(int []data) | |
{ | |
long time=System.currentTimeMillis(); | |
if(data==null || data.length<=1) | |
return; | |
for(int i=0,k=1;i<data.length-1;i++,k++) | |
swap(data,k); | |
System.out.println(System.currentTimeMillis()-time); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment