Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Arrays;
- import java.util.Comparator;
- import org.svetovid.io.SvetovidReader;
- public class Filmovi {
- public static void main(String[] args) {
- String fajl=Svetovid.in.readLine("Unesite naziv fajla: ");
- Film[] niz = ucitajFilmove(fajl);
- if (niz == null) {
- Svetovid.out.println("Dati fajl nije mogao da se procita! Proverite da li postoji.");
- return;
- }
- stampajNiz(niz);
- sortirajNiz(niz);
- Comparator c = new PoredjenjePoReditelju();
- sort(listaFilmova, c);
- for(Film i: listaFilmova) {
- System.out.println(i);
- }
- }
- public static Film[] ucitajFilmove(String fajl) {
- if(!Svetovid.testIn(fajl)) {
- return null;
- }
- SvetovidReader in=Svetovid.in(fajl);
- int br=in.readInt();
- Film[] rez=new Film[br];
- for (int i=0;i<br;i++) {
- int idf=in.readInt();
- String naziv=in.readLine();
- String reditelj=in.readLine();
- Film film =new Film(idf,naziv,reditelj);
- rez[i]=film;
- }
- Svetovid.closeIn(fajl);
- return rez;
- }
- public static void stampajNiz( Film[] niz) {
- for (Film a : niz) {
- Svetovid.out.printf(" (%4d) %20s %n", a.idf, a.naziv, a.reditelj);
- }
- }
- private static void sortirajNiz(Film[] niz) {
- Arrays.sort(niz);
- }
- static void sort(Film[] arr, Comparator<Film> c) {
- int n = arr.length;
- for(int i = 0; i < n-1; i++) {
- Film min = arr[i];
- int position = i;
- for(int j = i+1; j < n; j++) {
- if(c.compare(arr[j], min) < 0) {
- min = arr[j];
- position = j;
- }
- }
- Film temp = arr[i];
- arr[i] = arr[position];
- arr[position] = temp;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement