兴趣来了,编写一个求行列式的程序,关键要解决两个问题
1)行列式列序号的全排列
2)行列式的符号
#include <iostream>
#include <vector>
using namespace std;
#define LEN 3
#define COUNT 3*2*1 // the count of premutation for length 3
int idx[LEN] = { 0,1,2};
int premus[COUNT][LEN+1]; // last elemet for store inversion number
int premus_pos = 0;
int box[LEN][LEN] = { // sample data
{ 1, 2, 3 },
{ 4, 5, 5 },
{ 2, 4, 6 } };
void arrayCopy(int src[], int dst[]) {
for( int i=0; i<LEN; i++)
dst[i] = src[i];
}
int inveNumber(int a[]){ // return inversion number
int num = 0;
for(int i=1; i<LEN; i++){
for( int j=0; j<i; j++){
if ( a[i] < a[j])
num++;
}
}
return num;
}
void premu( int a[], int begin, int size) { // premutation
if ( begin == size-1){
arrayCopy( idx, premus[premus_pos]);
premus[premus_pos][