Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package org.foi.uzdiz.matsaboli2.factory_method;
- import org.foi.uzdiz.matsaboli2.Application;
- import org.foi.uzdiz.matsaboli2.data.Places;
- import org.foi.uzdiz.matsaboli2.data.Place;
- import org.foi.uzdiz.matsaboli2.iterator.Iterator;
- import org.foi.uzdiz.matsaboli2.iterator.PlacesIterator;
- /**
- *
- * @author Matija
- */
- public class AlgorithmIdAsc implements AlgorithmInterface {
- @Override
- public Places sort() {
- Iterator iterator = null;
- int min = 1001;
- Place min_place = null;
- Places places = new Places(Application.places.places.length);
- for (int i = 0; i < Application.places.places.length; i++) {
- iterator = new PlacesIterator(Application.places.places).getIterator();
- int temp = 9999;
- while (iterator.hasNext()) {
- Place temp_place = (Place) iterator.next();
- if (i == 0) {
- if (temp_place.getID() < min) {
- min = temp_place.getID();
- min_place = temp_place;
- }
- } else {
- if (temp_place.getID() < temp && temp_place.getID() > min) {
- temp = temp_place.getID();
- min_place = temp_place;
- }
- }
- }
- if (i != 0) {
- min = temp;
- }
- places.addPlace(min_place);
- }
- return places;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement