forked from cooperative-computing-lab/cctools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatrix.c
59 lines (45 loc) · 1018 Bytes
/
matrix.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
Copyright (C) 2009- The University of Notre Dame
This software is distributed under the GNU General Public License.
See the file COPYING for details.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "matrix.h"
struct matrix * matrix_create( int width, int height )
{
struct matrix *m = malloc(sizeof(*m));
m->width = width;
m->height = height;
m->data = malloc(sizeof(struct cell) * (m->width+1) * (height+1) );
return m;
}
void matrix_delete( struct matrix *m )
{
free(m->data);
free(m);
}
void matrix_print( struct matrix *m, const char *a, const char *b )
{
int i,j;
if(b) printf(" ");
if(a) for(i=0;i<m->width;i++) printf(" %c",a[i]);
printf("\n");
for(j=0;j<=m->height;j++) {
if(b) {
if(j>0) {
printf("%c ",b[j-1]);
} else {
printf(" ");
}
}
for(i=0;i<=m->width;i++) {
char t = matrix(m,i,j).traceback;
if(t==0) t=' ';
printf("%3d%c ",matrix(m,i,j).score,t);
}
printf("\n");
}
}
/* vim: set noexpandtab tabstop=4: */