Advertisement
Guest User

Untitled

a guest
Nov 19th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package org.foi.uzdiz.matsaboli2.factory_method;
  7.  
  8. import org.foi.uzdiz.matsaboli2.Application;
  9. import org.foi.uzdiz.matsaboli2.data.Places;
  10. import org.foi.uzdiz.matsaboli2.data.Place;
  11. import org.foi.uzdiz.matsaboli2.iterator.Iterator;
  12. import org.foi.uzdiz.matsaboli2.iterator.PlacesIterator;
  13.  
  14. /**
  15. *
  16. * @author Matija
  17. */
  18. public class AlgorithmIdAsc implements AlgorithmInterface {
  19.  
  20. @Override
  21. public Places sort() {
  22.  
  23. Iterator iterator = null;
  24. int min = 1001;
  25. Place min_place = null;
  26. Places places = new Places(Application.places.places.length);
  27.  
  28. for (int i = 0; i < Application.places.places.length; i++) {
  29.  
  30. iterator = new PlacesIterator(Application.places.places).getIterator();
  31. int temp = 9999;
  32.  
  33. while (iterator.hasNext()) {
  34. Place temp_place = (Place) iterator.next();
  35.  
  36. if (i == 0) {
  37. if (temp_place.getID() < min) {
  38. min = temp_place.getID();
  39. min_place = temp_place;
  40. }
  41. } else {
  42. if (temp_place.getID() < temp && temp_place.getID() > min) {
  43. temp = temp_place.getID();
  44. min_place = temp_place;
  45. }
  46. }
  47. }
  48.  
  49. if (i != 0) {
  50. min = temp;
  51. }
  52.  
  53. places.addPlace(min_place);
  54. }
  55.  
  56. return places;
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement