SHARE
TWEET

Untitled

a guest Sep 16th, 2019 88 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.mygdx.bubblesort;
  2.  
  3.  
  4. import com.badlogic.gdx.utils.Timer;
  5.  
  6. import java.util.ArrayList;
  7.  
  8. public class MyTask extends Timer.Task {
  9.  
  10.     private ArrayList<Vector4> list;
  11.     private int i = 0;
  12.  
  13.     public MyTask (ArrayList<Vector4> list){
  14.         this.list = list;
  15.     }
  16.  
  17.     @Override
  18.     public void run() {
  19.  
  20.         sort(list);
  21.     }
  22.  
  23.     void sort (ArrayList<Vector4> list) {
  24.  
  25.         if (i <= list.size()) {
  26.             for (int j = 0; j < list.size() - 1 - i; j++) {
  27.  
  28.                 if (list.get(j).getHeight() > list.get(j + 1).getHeight()) {
  29.  
  30.                     Vector4 temp = list.get(j);
  31.                     list.set(j, list.get(j + 1));
  32.                     list.set(j + 1, temp);
  33.  
  34.                 }
  35.             }
  36.         }
  37.         else {
  38.             System.out.println("Finished");
  39.             System.exit(0);
  40.         }
  41.  
  42.         i++;
  43.  
  44.         return;
  45.     }
  46.  
  47.     public ArrayList<Vector4> getList() {
  48.  
  49.         return list;
  50.     }
  51. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top