Beispiel #1
0
  void UpdateDilation(String womanName, int increaseDilation) { // UPDATE ITEM

    Woman mother = new Woman();
    mother.name = womanName;
    mother.dilation = increaseDilation;
    bh.Update(mother);
  }
Beispiel #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);
 }
Beispiel #3
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);
    }
  }
Beispiel #4
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);
 }
Beispiel #5
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;
    }
  }
Beispiel #6
0
 void ArriveAtHospital(String womanName, int dilation) { // INSERT ITEM
   Woman mother = new Woman();
   mother.name = womanName;
   mother.dilation = dilation;
   bh.Insert(mother);
 }