写了两天。。感觉确实需要多些代码了。T T
void give_global_traceback(sequence &seq1,sequence &seq2,sequence &alseq1,sequence &alseq2,int db[][k])
{ memset(alseq1.bp, 0, sizeof(char)*k); memset(alseq2.bp, 0, sizeof(char)*k); int a = 0, b = 0, c = 0; //从右下角开始找起,seq2是纵向序列,seq1是横向序列 int tb_i = seq1.size; //矩阵中横向的记录 int tb_j = seq2.size; //矩阵中纵向的记录 while(tb_i >= 0 || tb_j >= 0) { if(tb_i == 0 && tb_j == 0) //到左上角了,跳出 { break; } else if(tb_i == 0 && tb_j > 0) //到左边沿了,往上走 { alseq1.bp[al_i] = 'x'; tb_j--; alseq2.bp[al_j] = seq2.bp[tb_j]; } else if(tb_j == 0 && tb_i > 0) //到上边沿了,往左走 { alseq1.bp[al_i] = seq1.bp[tb_i]; tb_i--; alseq2.bp[al_j] = 'x'; } else { a = db[tb_j][tb_i-1]; b = db[tb_j-1][tb_i]; c = db[tb_j-1][tb_i-1]; if (a > b && a > c) //对纵向序列插空 { alseq1.bp[al_i] = seq1.bp[tb_i - 1]; tb_i--; alseq2.bp[al_j] = 'x'; } else if (b > a && b > c) //对横向序列插空 { alseq1.bp[al_i] = 'x'; tb_j--; alseq2.bp[al_j] = seq2.bp[tb_j - 1]; } else //不插空 { alseq1.bp[al_i] = seq1.bp[tb_i - 1]; alseq2.bp[al_j] = seq2.bp[tb_j - 1]; tb_i--; tb_j--; } } al_i++; al_j++; }}