Exemple #1
0
// move element i up in the tree until
// the heap condition (all nodes have values
// less than the values of their children)
// is restored
void rise( PriorityQueuePointer pq, int i ) {
  int j = i/2;
  if( i > 1 && compareElements(pq, i, j) < 0 ) {
    swap( pq, i, j );
    //int temp = pq->data[i];
    //pq->data[i] = pq->data[j];
    //pq->data[j] = temp;

    rise( pq, j );
  } // if
} // rise( int[], int )
Exemple #2
0
// move an element down in the tree
// until the heap condition (value of each
// node is less than the value of its children)
// is restored
void fall( PriorityQueuePointer pq, int i ) {
  // i is the index of a parent node in the heap
  // j and k are the indices of its children
  // choose the smaller of the children
  int j = 2 * i;
  int k = 2 * i + 1;
  if( k <= pq->size && compareElements( pq, k, j) < 0 ) {
    j = k;
  } // if

  // do not fall too far!
  // stop falling when heap condition has 
  // been stored
  if( j <= pq->size && compareElements(pq, j, i) < 0 ) {
    swap( pq, i, j );
    //int temp = pq->data[i];
    //pq->data[i] = pq->data[j];
    //pq->data[j] = temp;

    fall( pq, j );
  } // if
} // fall( PriorityQueuePointer, int )
int BSONElement::woCompare(const BSONElement& elem,
                           ComparisonRulesSet rules,
                           const StringData::ComparatorInterface* comparator) const {
    if (type() != elem.type()) {
        int lt = (int)canonicalType();
        int rt = (int)elem.canonicalType();
        if (int diff = lt - rt)
            return diff;
    }
    if (rules & ComparisonRules::kConsiderFieldName) {
        if (int diff = fieldNameStringData().compare(elem.fieldNameStringData()))
            return diff;
    }
    return compareElements(*this, elem, rules, comparator);
}
int main()
{
    //Guide users to input matrix row by row.
    printf("Please input a 4x4 matrix.\n");
    float matrix[4][4];
    printf("Please input the first row, divide each elements by \",\".\n");
    scanf("%f,%f,%f,%f", &matrix[0][0], &matrix[0][1], &matrix[0][2], &matrix[0][3]);
    printf("Please input the second row, divide each elements by \",\".\n");
    scanf("%f,%f,%f,%f", &matrix[1][0], &matrix[1][1], &matrix[1][2], &matrix[1][3]);
    printf("Please input the third row, divide each elements by \",\".\n");
    scanf("%f,%f,%f,%f", &matrix[2][0], &matrix[2][1], &matrix[2][2], &matrix[2][3]);
    printf("Please input the fourth row, divide each elements by \",\".\n");
    scanf("%f,%f,%f,%f", &matrix[3][0], &matrix[3][1], &matrix[3][2], &matrix[3][3]);
    
    //Initialize varibles which will be used below.
    int row;
    int col;
    //This varible is used to recive return values from the function compareElements.
    int compareReturn = 0;
    int breakCount = 0;
    
    //Foreach array matrix.
    for (row = 0, col = 3; row <= 3, col >= 0; row++, col--)
    {
        //Call function to compare selected elements.
        compareReturn = compareElements(matrix[row][col], matrix[col][row]);
        //Judgement by each returns. Once there is a fail return 0, break the loop and print fail infomation.
        if (compareReturn == 0)
        {
            breakCount++;
        }
    }
    int printMatrix;
    for (printMatrix=0;printMatrix<4;printMatrix++)
    {
        printf("%f  %f  %f  %f",matrix[printMatrix][0],matrix[printMatrix][1],matrix[printMatrix][2],matrix[printMatrix][3]);
        printf("\n");
    }
    if (breakCount == 0)
        printf("This martix is symmtery.\n");
    else
        printf("This martix isn't symmtery.\n");
    return 0;
}
Exemple #5
0
bool compareScores(Score* score1, Score* score2)
      {
      int staves = score1->nstaves();
      if (score2->nstaves() != staves) {
            printf("   stave count different\n");
            return false;
            }
      Segment* s1 = score1->firstMeasure()->first();
      Segment* s2 = score2->firstMeasure()->first();

      int tracks = staves * VOICES;
      for (;;) {
            for (int track = 0; track < tracks; ++track) {
                  Element* e1 = s1->element(track);
                  Element* e2 = s2->element(track);
                  if ((e1 && !e2) || (e2 && !e1)) {
                        printf("   elements different\n");
                        return false;
                        }
                  if (e1 == 0)
                        continue;
                  if (!compareElements(e1, e2)) {
                        printf("   %s != %s\n", e1->name(), e2->name());
                        return false;
                        }
                  printf("   ok: %s\n", e1->name());
                  }
            s1 = s1->next1();
            s2 = s2->next1();
            if ((s1 && !s2) || (s2 && !s2)) {
                  printf("   segment count different\n");
                  return false;
                  }
            if (s1 == 0)
                  break;
            }
      return true;
      }