标签:向量 linked this 分享图片 conf 宽度 enc 一个 tran
template <class T> struct MTNode{ int i, j; T e; }; template <class T> typedef struct L { MTNode<T> *data; int mu, nu, tu; }TSMatrix;
template <class T> struct MTNode{ int i, j; T e; }; typedef struct L { MTNode *data; int *rpos /*the index of evey firstnotnull in the row TSMtrix.*/ int mu,nu,tu; }SMatrix;
typedef struct L { MTNode *data; int *rpos /*the index of evey firstnonull in the row TSMtrix.*/ int mu,nu,tu; }SMatrix;
struct MTNode{ int i, int j; T e; MTNode * dowm; MTNode * right; //used to bulid linked list } typedef struct L { int mu,nu,tu; MTNode *rpos; MTNode *cpos; }LMatrix;
void MatrixTrans_I(TSMatrix A, TSMatrix &B){ B.mu = A.nu; B.nu = A.mu; B.tu = A.tu; //A convert the arguments to B; if(B.tu) //confirm it has element { q = 0; //q is the index of the TSMatrix B for(col = 0; col < A.nu; col++) for(p = 0; p < A.mu; p++) //p is the index of the TSMatrix A //search every row. if(A.data[p].j == col) { B.data[q].i = A.data[p].j; B.data[q].j = A.data[p].i; B.data[q].e = A.data[p].e; ++q; } } }
void MatrixTrans_II(TSMatrix A, TSMatrix &B){ B.mu = A.nu; B.nu = A.mu; B.tu = A.tu; int i, k, p,q; int * num, * cpot; num = new int[B.nu]; cpot = new int[B.nu]; if(B.tu){ for(i = 0; i < B.nu; i++){ num[i] = 0; //initialization } for(k = 0; k < B.nu; k++){ num[A.data[k].j]++; //counter } copt[0] = 0; for(k = 1; k < B.nu; k++){ cpot[k] =copt[k - 1] + num[k - 1]; } for(p = 0; p < A.nu; p++){ //get the elemnt int A in sequence //and then insert it into the right //postion. q = copt[A.data[p].j]; B.data[q].i = A.data[p].j; B.data[q].j = A.data[p].i; B.data[q].e = A.data[p].e; copt[A.data[p].j]++; } } }
enum Elemtag{Atom,List}; //0 is atom node, 1 is list node; template <class T> struct GLNode { Elemtag tag; union { T data; struct { GLNode * hp, *tp; }ptr; }; };
enum Elemtag{Atom, List}; template <class T> struct GLNode { Elemtag tag; union{ T data; struct GLnode* hp; //hp point to the son } struct GLNode *tp; //tp point to the brother }ptr;
int depth(GLNode * ls){ int h,t; if(ls == NULL)//if the node is not exist return 1 return 1; else if(ls -> tag == 0) return 0;//if the node is atom return 0 else { h = depth(ls -> hp); t = depth(ls -> tp); if(t > h) return t; else return h+1; //recursion } }
int Length(GLNode *ls){ if(ls == NULL) return 0; int max = 1; //search in y GLNode* p = ls -> tp; while(p){ max++; p = p -> tp; } return max; }
template <class T> GLNode<T>* Crtlists(string st){ if(st == "()") ls = NULL; else if(st.Length() == 1){ ls = new GLNode<T>; ls -> tag = 0; ls -> data = st[0]; } else { ls = new GLNode<T>; ls -> data = 1; p = ls; st = st.substring(1, st.length()-2); //remove the "()" do{ Server(sub,hsub); p -> ptr.hp = Crtlists(hsub); q = p; //This is a sub remove "()"outside //and the element in it. if(sub!="") { p = new GLNode<T>; p -> tag = 1; q -> ptr.tp = p; }; } while(sub != ""); q -> ptr.tp = NULL;//seal the last one. } return(ls); }
这个章节的内容理解并不是很难,要是想要实现各种递归还真的是头疼。。。
标签:向量 linked this 分享图片 conf 宽度 enc 一个 tran
原文地址:https://www.cnblogs.com/dreamworldclark/p/9939770.html