private List <string[]> taoBangMoi(List <string[]> Tab, giatriTT T, int posMax) { List <string[]> Tab1 = new List <string[]>(); int m = Tab.Count; int n = Tab[0].Length; string[] temps = new string[n - 1]; int k = 0; for (int i = 0; i < n; i++) { if (Tab[0][i] != Tab[0][posMax]) { temps[k++] = Tab[0][i]; } } Tab1.Add(temps); for (int i = 0; i < m; i++) // Duyet theo hang Table ban dau { // Neu hang co (gia tri thuoc tinh dang xet) bang voi // (gia tri can phan hoach) thi tinh if (Tab[i][posMax] == T.value) { temps = new string[n - 1]; k = 0; for (int j = 0; j < n; j++) { if (j != posMax) { temps[k++] = Tab[i][j]; } } Tab1.Add(temps); } } return(Tab1); }
private List <giatriTT> hamtimTT(List <string[]> Tab, ref int posMax) { /* * Ham tim thuoc tinh phan loai * Input: Table, posMax (Index cua thuoc tinh phan loai trong Table) * Output: List<giatriTT> list gia tri thuoc tinh */ int m = Tab.Count; int n = Tab[0].Length; List <List <giatriTT> > T = new List <List <giatriTT> >(); int[][] Count = new int[n - 2][]; for (int i = 0; i < n - 2; i++) { Count[i] = new int[2]; Count[i][0] = 0; } int t = 0; // Bien chay cho T giatri TT // moi thuoc tinh co mot vector<giatriTT> T; int max = 0, smin = 0; for (int j = 1; j <= n - 2; j++) { // Duyet qua cac thuoc tinh, toc, chieucao,.... List <giatriTT> tempTT = new List <giatriTT>(); // lay gia tri thuoc tinh o dong dau tien giatriTT temp = new giatriTT(); temp.value = Tab[1][j]; temp.check = Tab[1][n - 1]; // gia tri thuoc tinh dich tempTT.Add(temp); // lay gia tri cua thuoc tinh o 2->m-1 dong ke tiep for (int i = 2; i <= m - 1; i++) { //T[t].size = so luong gia tri cua thuoc tinh int f = 1; for (int z = 0; z < tempTT.Count; z++) { if (Tab[i][j] == tempTT[z].value) {// neu da co gia tri thuoc tinh f = 0; //if (T[t][z].flag == 0) { //b = 1; break; //} // khong la vector donvi //if (b == 1) break; if (Tab[i][n - 1] != tempTT[z].check) { tempTT[z].flag = 0; } break; } //if (b == 1) break; } if (f == 0) { continue; } // neu cua co gtri trong T[t] temp = new giatriTT(); temp.value = Tab[i][j]; temp.check = Tab[i][n - 1]; tempTT.Add(temp); } for (int z = 0; z < tempTT.Count; z++) { Count[t][0] += tempTT[z].flag; // dem o vector donvi } // So luong gia tri cua thuoc tinh dang xet Count[t][1] = tempTT.Count; if (t == 0) { max = Count[t][0]; smin = Count[t][1]; posMax = t + 1; } if (Count[t][0] > max) { max = Count[t][0]; smin = Count[t][1]; posMax = t + 1; } else if (Count[t][0] == max) { if (Count[t][1] < smin) { max = Count[t][0]; smin = Count[t][1]; posMax = t + 1; } } T.Add(tempTT); t++; // vector T<giatriTT> tiep theo; } return(T[posMax - 1]); }