三元グループ(疎行列の回転)

2098 ワード

//           ,     ,             ,      ,                    。  ,          
//        “   ”,               。
// 2017/10/15
#include
using namespace std;


//--------         ----------
#define MAX_SIZE 10000  
#define MAX_ROW_SIZE 100
#define MAX_COL_SIZE 100
typedef int ElemType;
class Triple_node{
public:
	int i, j;  // i j               , 1    
	ElemType e;
	friend istream& operator>>(istream &is, Triple_node &node); //     
	friend ostream& operator<>(istream &is, Triple_node &node) //     
{
	cout << "  (  ,  ,   )         :
"; is >> node.i >> node.j >> node.e; return is; } ostream& operator<> row >> col; Triple_node node; int cnt=0; while (cin>>node) { cnt++; data[cnt].i = node.i; data[cnt].j = node.j; data[cnt].e = node.e; } nums = cnt; } void TSmatrix::print() { cout << " :
"; for (int i = 1; i <= nums; i++) { cout << data[i]; } } void TSmatrix::Transpose(TSmatrix &t) // { t.col = row; t.row = col; t.nums = nums; if (nums == 0) { cout << " ,
"; return; } int num[MAX_COL_SIZE+1]; // num , int copt[MAX_COL_SIZE+1]; // copt , // for (int i = 1; i <= col; i++) { num[i] = 0; } for (int count = 1; count <= nums; count++) { num[data[count].j]++; // } copt[1] = 1; for (int i = 2; i <= col; i++) { copt[i] = copt[i - 1] + num[i - 1]; } // int this_col, destnation; for (int origin = 1; origin <=nums; origin++) { this_col = data[origin].j; destnation = copt[this_col]; t.data[destnation].i = data[origin].j; t.data[destnation].j = data[origin].i; t.data[destnation].e = data[origin].e; copt[this_col]++; } } int main() { TSmatrix tsmatrix; TSmatrix t = tsmatrix; tsmatrix.print(); tsmatrix.Transpose(t); t.print(); }