Ejemplo n.º 1
0
 void fold_horiz(vector<vector<int>> &M){
     int i = 0;
     int j = (int)M.size()-1;
     
     while(i < j){
         swap_col(M, i, j);    
         i++;
         j--;
     }
 }
Ejemplo n.º 2
0
int swap_matrix_row_col(matrix_t *m, int row_or_col, char *buf, int buf_size)
{
    int idx1 = 0, idx2 = 0;
    int max_idx = 0;
    char *row_or_col_str;
    if (row_or_col == SWAP_ROW)
    {
        row_or_col_str = "Row";
        max_idx = m->num_rows;
    }
    else if (row_or_col == SWAP_COL)
    {
        row_or_col_str = "Column";
        max_idx = m->num_cols;
    }
    else
    {
        return FAIL;
    }

    printf("Enter %s Index 1: ", row_or_col_str);
    if (readnum(buf, buf_size, &idx1) == ERROR)
        return ERROR;
    if (idx1 >= max_idx)
    {
        printf("Bad Input\n");
        return FAIL;
    }

    printf("Enter %s Index 2: ", row_or_col_str);
    if (readnum(buf, buf_size, &idx2) == ERROR)
        return ERROR;
    if (idx2 >= max_idx)
    {
        printf("Bad Input\n");
        return FAIL;
    }

    print_matrix("Original Matrix", m);
    if (row_or_col == SWAP_ROW)
        return swap_row(m, idx1, idx2);
    if (row_or_col == SWAP_COL)
        return swap_col(m, idx1, idx2);

    return FAIL;
}
Ejemplo n.º 3
0
qint16 BulkHeaderGroup::levenshteinDistance(const QString& a_compare1, const QString& a_compare2)
{
    const qint16 length1 = a_compare1.size();
    const qint16 length2 = a_compare2.size();
    QVector<qint16> curr_col(length2 + 1);
    QVector<qint16> prev_col(length2 + 1);

    // Prime the previous column for use in the following loop:
    for (qint16 idx2 = 0; idx2 < length2 + 1; ++idx2)
    {
        prev_col[idx2] = idx2;
    }

    for (qint16 idx1 = 0; idx1 < length1; ++idx1)
    {
        curr_col[0] = idx1 + 1;

        for (qint16 idx2 = 0; idx2 < length2; ++idx2)
        {
            const qint16 compare = a_compare1[idx1] == a_compare2[idx2] ? 0 : 1;

            curr_col[idx2 + 1] = qMin(qMin(curr_col[idx2] + 1, prev_col[idx2 + 1] + 1),
                    prev_col[idx2] + compare);
        }

#if defined(Q_OS_OS2) || defined(Q_OS_OS2EMX) // In qglobal.h
    QVector<qint16> swap_col(length2 + 1);

    swap_col = prev_col;
    prev_col = curr_col;
    curr_col = swap_col;
#else
     curr_col.swap(prev_col);
#endif
    }

    return prev_col[length2];
}
Ejemplo n.º 4
0
 //swap two rows and columns
 inline void swap_row_col(int c1, int c2) {
   swap_col(c1,c2);
   swap_row(c1,c2);
 }