Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- scoring_matrix create_matrix(const char *a, const char *b, int match_score, int gap_cost)
- {
- int height = strlen(a)+1;
- int width = strlen(b)+1;
- int* flatrix = malloc((height*width)*sizeof(int));
- memset(flatrix, 0, (height*width)*sizeof(int));
- int val, rowC, colC, topVal, leftVal, cornerVal;
- for(rowC = 1; rowC < height; rowC++){
- for(colC = 1; colC < width; colC++){
- topVal = (flatrix[(width*(rowC-1))+colC] - gap_cost);
- leftVal = (flatrix[(width*rowC)+(colC-1)] - gap_cost);
- cornerVal = flatrix[(width*(rowC-1))+(colC-1)];
- if((a[rowC-1]) == (b[colC-1])){
- cornerVal = cornerVal + match_score;
- }else{
- cornerVal = cornerVal - match_score;
- }
- val = 0;
- if(topVal > val){
- val = topVal;
- }if(leftVal > val){
- val = leftVal;
- }if(cornerVal > val){
- val = cornerVal;
- }flatrix[(width*rowC)+colC] = val;
- }
- }
- scoring_matrix matrix = {width, height, flatrix};
- return matrix;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement