Advertisement
davegimo

Es1 Grafi

Feb 3rd, 2020
591
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.10 KB | None | 0 0
  1. import java.util.ArrayList;
  2.  
  3. public class Grafo {
  4.  
  5.   private ArrayList<Nodo> nodi;
  6.   private Arco[][] matriceAdiacenza;
  7.  
  8.   public boolean grafoProprio(Grafo g) {
  9.  
  10.  
  11.     for (int i = 0; i< matriceAdiacenza.length ; i++) {
  12.  
  13.       if (!nodi.get(i).isUtente()) {    // Il nodo è un brand
  14.  
  15.       for (int j = 0; j< matriceAdiacenza[i].length ; j++) {
  16.  
  17.         if (!nodi.get(j).isUtente() && matriceAdiacenza[i][j] == 1) {
  18.           return false;
  19.         }
  20.       }
  21.  
  22.       }
  23.     }
  24.  
  25.     return true;
  26.   }
  27.  
  28.   public Collection influencer(Grafo g, Utente u) {
  29.  
  30.     ArrayList<Nodo> listBrand = new ArrayList<Nodo> ();
  31.  
  32.     int index = nodi.indexOf(u);
  33.  
  34.     int contaUtenti = 0;
  35.     int contaBrand = 0;
  36.  
  37.  
  38.     for (int i = 0; i < matriceAdiacenza[index].length; i++) {
  39.  
  40.       if (matriceAdiacenza[index][i] == 1) {
  41.  
  42.         if (nodi.get(i).isUtente()) {
  43.           contaUtenti++;
  44.         }
  45.  
  46.         else {
  47.           contaBrand++;
  48.           listBrand.add(nodi.get(i));
  49.         }
  50.       }
  51.     }
  52.  
  53.  
  54.    if (contaUtenti > contaBrand) {
  55.  
  56.     return listBrand;
  57.    }
  58.  
  59.    return null;
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement