Пример #1
0
  void UpdateDilation(String womanName, int increaseDilation) { // UPDATE ITEM

    Woman mother = new Woman();
    mother.name = womanName;
    mother.dilation = increaseDilation;
    bh.Update(mother);
  }
Пример #2
0
 void Update(Woman mother) {
   Woman temp;
   int i = getNameIndex(mother.name);
   temp = A.get(i);
   temp.dilation = A.get(i).dilation + mother.dilation;
   temp.name = A.get(i).name;
   temp.order = A.get(i).order;
   A.set(i, temp);
   shiftUp(i);
   shiftDown(i);
 }
Пример #3
0
  public static void main(String[] args) {
    // создай по два объекта каждого класса тут
    Man man1 = new Man("kol", 25, "address");
    Man man2 = new Man("pol", 27, "address");
    Woman woman1 = new Woman("sara", 21, "address");
    Woman woman2 = new Woman("molly", 23, "address");

    // выведи их на экран тут
    Man.getMan(man1);
    Man.getMan(man2);
    Woman.getWoman(woman1);
    Woman.getWoman(woman2);
  }
Пример #4
0
  public void getPartner(Person person) {
    // 将搭档设置上
    if (person instanceof Man) {
      this.setMan((Man) person);
    } else {
      this.setWoman((Woman) person);
    }

    // 判断条件
    if (man == null || woman == null) { // 证明有重复设置
      System.out.println("汗!我不是同性恋");
    } else {
      if (man.getCondition() == woman.getCondition()) {
        System.out.println(man.getName() + "和" + woman.getName() + "绝配");
      } else {
        System.out.println(man.getName() + "和" + woman.getName() + "不相配");
      }
    }
  }
Пример #5
0
  void shiftUp(int i) {
    Woman temp = A.get(i);
    Woman temp2;
    temp.index = i;
    while (i > 1 && A.get(parent(i)).dilation <= A.get(i).dilation) {
      if (A.get(parent(i)).dilation == A.get(i).dilation
          && A.get(parent(i)).order < A.get(i).order) {
        break;
      }

      temp = A.get(i);
      temp2 = A.get(parent(i));
      temp.index = parent(i);
      temp2.index = i;
      A.set(i, temp2);
      A.set(parent(i), temp);
      i = parent(i);
    }
  }
Пример #6
0
 void Insert(Woman mother) {
   BinaryHeapSize++;
   binaryHeapOrder++;
   mother.order = binaryHeapOrder;
   B.put(mother.name, mother);
   if (BinaryHeapSize >= A.size()) {
     A.add(mother);
   } else {
     A.set(BinaryHeapSize, mother);
   }
   shiftUp(BinaryHeapSize);
 }
Пример #7
0
 public static void main(String args[]) {
   BathroomController c = new BathroomController();
   Man m1 = new Man(c, 1);
   Man m2 = new Man(c, 2);
   Man m3 = new Man(c, 3);
   Woman w1 = new Woman(c, 1);
   Woman w2 = new Woman(c, 2);
   Woman w3 = new Woman(c, 3);
   m1.start();
   w1.start();
   m2.start();
   w2.start();
   m3.start();
   w3.start();
   try {
     m1.join();
     w1.join();
     m2.join();
     w2.join();
     m3.join();
     w3.join();
   } catch (InterruptedException e) {
   }
 }
Пример #8
0
  void shiftDown(int i) {
    Woman temp = A.get(i);
    Woman temp2;
    temp.index = i;

    boolean isLeft = true;
    boolean isRight = true;

    while (i <= BinaryHeapSize) {
      isLeft = true;
      isRight = true;

      int leftMax = 0, leftMaxId = 0;
      int rightMax = 0, rightMaxId = 0;

      int maxV = A.get(i).dilation, max_id = i;
      if (left(i) <= BinaryHeapSize && maxV <= A.get(left(i)).dilation) {
        if (maxV == A.get(left(i)).dilation) {
          if (A.get(i).order < A.get(left(i)).order) isLeft = false;
        }
        if (isLeft) {
          leftMax = A.get(left(i)).dilation;
          leftMaxId = left(i);
        }
      }

      if (right(i) <= BinaryHeapSize && maxV <= A.get(right(i)).dilation) {
        if (maxV == A.get(right(i)).dilation) {
          if (A.get(i).order < A.get(right(i)).order) isRight = false;
        }
        if (isRight) {
          rightMax = A.get(right(i)).dilation;
          rightMaxId = right(i);
        }
      }

      if (rightMax > leftMax) {
        maxV = A.get(right(i)).dilation;
        max_id = right(i);
      } else if (rightMax < leftMax) {
        maxV = A.get(left(i)).dilation;
        max_id = left(i);
      } else if (rightMax == leftMax) {
        if (A.get(rightMaxId).order > A.get(leftMaxId).order) {
          maxV = A.get(left(i)).dilation;
          max_id = left(i);
        } else if (A.get(rightMaxId).order < A.get(leftMaxId).order) {
          maxV = A.get(right(i)).dilation;
          max_id = right(i);
        }
      }

      if (max_id != i) {
        temp = A.get(i);
        temp2 = A.get(max_id);
        temp.index = max_id;
        temp2.index = i;
        A.set(i, temp2);
        A.set(max_id, temp);
        i = max_id;
      } else break;
    }
  }
Пример #9
0
 void ArriveAtHospital(String womanName, int dilation) { // INSERT ITEM
   Woman mother = new Woman();
   mother.name = womanName;
   mother.dilation = dilation;
   bh.Insert(mother);
 }