Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- public class ShellSort {
- public static void main(String args[]){
- ArrayList<Integer> list = new ArrayList<Integer>();
- for (int i=0;i < 100;i++){
- list.add((int)(Math.random()*200)+1);
- System.out.print(list.get(i)+" ");
- }
- for( int gap = list.size() / 2; gap > 0; gap = gap == 2 ? 1 : (int) ( gap / 2.2 ) ){
- for( int i = gap; i < list.size(); i++ ){
- int tmp = list.get(i);
- int j;
- for(j = i; j >= gap && tmp < list.get(j - gap) ; j -= gap ){
- list.set(j, list.get(j - gap));
- }
- list.set(j, tmp);
- }
- }
- System.out.println("Ordenado");
- for(int i=0; i<100; i++){
- System.out.print(list.get(i)+" ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement