Разработка алгоритмов и программ выполнения операций над последовательными и связанными представлениями структур данных — страница 5
fun2(double N_X,double N_Y,double N_Z){ return N_X+N_Y;} inline double fun3(double N_X,double N_Y,double N_Z){ return N_X;} inline double fun4(double N_X,double N_Y,double N_Z){ return N_Y;} inline double fun5(double N_X,double N_Y,double N_Z){ return N_Z;} inline double fun6(double N_X,double N_Y,double N_Z){ return 1;} /////////////////////////////////////////////////////////////////////////////////////////////////////// const int N = 6, M = N+1; double A[N][M]; double B[N][M]; typedef double(*MENU1)(double,double,double); MENU1 MyMenu[6] = { fun1,fun2,fun3,fun4, fun5,fun6 }; //////////////////////////////////////////////////////////////////////////////// int gordanA(int n, int m) { int i, j, k, ir; double s, c; for (j = 0; j < n; j++){ for (s = 0, i = 0; i < (n - j); i++)if (fabs(A[i][j]) > fabs(s)) s = A[ir = i][j]; if(s==0)return -1; for (k = j + 1; k < m; k++){ c = A[ir][k]/s; for (i = 0; i < ir; i++)A[i][k] -= c * A[i][j]; for (i = ir + 1; i < n; i++)A[i - 1][k] = A[i][k] - c * A[i][j]; A[n - 1][k] = c; } } return 0; } /////////////////////////////////////////////////////////////////////////////// long double Stp(int a, int n) { long double c,bi; int k; c=1; k=n; bi=a; while(k>0){ if(k%2==1)c*=bi; bi*=bi; k/=2; } return c; } /////////////////////////////////////////////////////////////////////////////////////////////////////// void CursorOff(void) {asm{ mov ah,1 mov ch,0x20 int 0x10 } } /////////////////////////////////////////////////////////////////////////////////////////////////////// Spisok **GenSeY(int Mas_y,int & Counter) { Counter=0; Spisok **Y = new Spisok* [Mas_y]; for (int i = 0; i< Mas_y; i++){ int m = 0; int *Pro = new int [Mas_y]; Spisok *beg = NULL, *end = NULL ; for (int j = 0; j< Mas_y; j++){ int k = random(Mas_y); int flag = 0; for (int j = 0; j< m; j++)if (k==Pro[j]) flag = 1; if (k != 0 && flag == 0){ Pro[m] = k; m++; if ((beg==NULL) && (end==NULL)){ end=new(Spisok); if (end == NULL) {cout << "Lack of memory";exit (1);} beg=end; } else{ end=end->next=new (Spisok); if (end==NULL) {cout <<"L a c k of m e m o r y !"; exit (1);} } end->next=NULL; end->index = k; Counter++; } } Y [i] = beg; delete [] Pro; } return Y; } //////////////////////////////////////////////////////////////////////////////// Array *GenSeX(int Mas_y,int & Counter) { Counter=0; Array *X = new Array[Mas_y*Mas_y]; if(X==NULL){cout<<"\n net u mena stolko pamaty!!!\n";exit(1);} randomize(); for (int i = 0; i< Mas_y; i++){ int m = 0; int *Pro = new int [Mas_y]; for (int j = 0; j< Mas_y; j++){ int k = random(Mas_y); int flag = 0; for (int j = 0; j< m; j++)if (k==Pro[j]) flag = 1; if (k != 0 && flag == 0){ X[Counter].I=i; X[Counter].J=k; Pro[m] = k; m++; Counter++; } } delete [] Pro; } return X; } //////////////////////////////////////////////////////////////////////////// int Number(int & kol2,char *st ) { int N; ifstream file; int kol1 = 0; kol2 = 0; file.open(st); if (!file) cerr <<"Can not open file!!!!!"; else {file >> N; file.get(); for( int i = 0; i <2*N ; i++) {char *string = new char[3*N]; file.getline(string,3*N,'\n'); for( int j = 0; string[j] != '0' ; j++ ) {if (string[j] == ' ') //{if((j%2!=0)||(j > N*3)) // {cout <<"error in file "<<st;return 0;} if (i<N) kol1++; else kol2 ++; } delete [] string; } } file.close(); //cout << kol1 <<"\t"<< kol2; return kol1; } //////////////////////////////////////////////////////////////////////////////// Array *ReadFileX(Array *X,char * st ) { ifstream file; int n; file.open(st); if (!file) cerr <<"Can not open file!!!!!"; else {file >> n; file.get(); int k = 0,n1=0; for(int i=0; i < n; i++){ file >> n1; while (n1 != 0){ X[k].I = i; X[k].J = n1-1; k++; n1=0; file >> n1; //cout << X[k-1].I<< "\t"<<X[k-1].J<<"\n" ; } } } file.close(); return X; } //////////////////////////////////////////////////////////////////////////////// Spisok **ReadFileY(Spisok **Y,char *st ) { int n;; ifstream file; file.open(st); if (!file) cerr <<"Can not open file!!!!!"; else {file >> n; file.get(); for(int i=0; i < n; i++) { char *string = new char[580]; if (string == NULL) {cout << "Lack of memory";exit(1);} file.getline(string,580,'\n'); delete [] string; } for(int j=0; j < n; j++) { int n1; file >> n1; Spisok *beg=NULL,*end = NULL; while (n1 != 0) { if ((beg==NULL) && (end==NULL)) { end=new(Spisok); if (end == NULL) {cout << "Lack of memory";exit (1);} beg=end;}
Похожие работы
- Доклады
- Рефераты
- Рефераты
- Рефераты
- Контрольные