void Quicksort(int low,int high) { /*对R[low...high]的快速排序*/ int pivotpos,k; if (low<high) { /*当区间长度大于1时才需排序*/ pivotpos=Partition(low,high); num++; if(m==num) { printf("第%d趟的结果是:",m); for (k=1; k<=n; k++) printf("%5d",R[k].key); printf("\n"); printf("请输入还要输出第几趟结果,不想输出时请输入0:"); scanf("\n%d",&m); } Quicksort(low,pivotpos-1); Quicksort(pivotpos+1,high); } if(low==1&&high==n) { printf("最终排序结果是:"); for (k=1; k<=n; k++) printf("%5d",R[k].key); printf("\n"); /*printf("请输入还要输出第几趟结果,不想输出时请输入0:");*/ /*scanf("\n%d",&m);*/ } }/*Quicksort*/
void Tools::Quicksort(Cube list[], const int64_t left, const int64_t right) { if (left < right) { int64_t pivot_index = (left + right) >> 1; int64_t pivot_new_index = Partition(list, left, right, pivot_index); Quicksort(list, left, pivot_new_index - 1); Quicksort(list, pivot_new_index + 1, right); }
void Quicksort( int *array, int left, int right, int delay_factor ) { int i, j, t; if ( right > left ) { i = left - 1; j = right; do { do i++; while ( array[i] < array[right] ); do j--; while ( array[j] > array[right] && j > 0 ); t = Swap_Pixels( array, i, j, delay_factor ); } while ( j > i ); putpixel( 3*j, *(array + j), 0); array[j] =array[i]; putpixel( 3*j, *(array + j), 10 ); putpixel( 3*i, *(array + i), 0 ); array[i] =array[right]; putpixel( 3*i, *(array + i), 10 ); putpixel( 3*right, *(array + right), 0 ); array[right] = t; putpixel( 3*right, *(array + right), 10 ); Quicksort( array, left, i - 1, delay_factor ); Quicksort( array, i + 1, right, delay_factor ); } }
void Quicksort(__int64_t a[], int left, int right, int p_nType) { int last = left, i; if(left >= right) return; Swap(a, left, Random(left, right)); for(i = left + 1; i <= right; ++i) { if(SORT_LARGE_SMALL == p_nType) { if(a[i] > a[left]) Swap(a, ++last, i); } else if(SORT_SMALL_LARGE == p_nType) { if(a[i] < a[left]) Swap(a, ++last, i); } } Swap(a, left, last); Quicksort(a, left, last - 1, p_nType); Quicksort(a, last + 1, right, p_nType); }
void Quicksort(int a[],int p,int r) { if(p<r) { int q=Partition(a,p,r); Quicksort(a,p,q-1); Quicksort(a,q+1,r); } }
void Dim::Quicksort( float** d, int left, int right) { if(left < (right- 15)) { int split_pt = Partition(d,left, right); Quicksort(d, left, split_pt); Quicksort(d, split_pt+1, right); } else SelectionSort(d, left, right); };
/* This is a general quicksort algorithm, using median-of-three strategy. * * Parameters: * =========== * a: array of items to be sorted (list of void pointers). * l: left edge of sub-array to be sorted. Toplevel call has 0 here. * r: right edge of sub-array to be sorted. Toplevel call has |a| - 1 here. * CompareFunc: Pointer to a function that accepts two general items d1 and d2 * and returns values as follows: * * < 0 --> d1 "smaller" than d2 * > 0 --> d1 "larger" than d2 * 0 --> d1 "==" d2. * * See sample application in ipc.c's IPC_Help. */ void Quicksort(void **a, int l, int r, int (*CompareFunc) (const void *d1, const void *d2)) { int i, j, m; void *v, *t; if (r > l) { m = (r + l) / 2 + 1; if (CompareFunc(a[l], a[r]) > 0) { t = a[l]; a[l] = a[r]; a[r] = t; } if (CompareFunc(a[l], a[m]) > 0) { t = a[l]; a[l] = a[m]; a[m] = t; } if (CompareFunc(a[r], a[m]) > 0) { t = a[r]; a[r] = a[m]; a[m] = t; } v = a[r]; i = l - 1; j = r; for (;;) { while (CompareFunc(a[++i], v) < 0) ; while (CompareFunc(a[--j], v) > 0) ; if (i >= j) break; t = a[i]; a[i] = a[j]; a[j] = t; } t = a[i]; a[i] = a[r]; a[r] = t; Quicksort(a, l, i - 1, CompareFunc); Quicksort(a, i + 1, r, CompareFunc); } }
void TypeIIRMLMath::Quicksort( const int &LeftBound , const int &RightBound , double *ArrayOfValues) { int FirstLoopVariable , SecondLoopVariable; double CurrentValue , HelpVariable; CurrentValue = ArrayOfValues[(LeftBound + RightBound) / 2] ; FirstLoopVariable = LeftBound ; SecondLoopVariable = RightBound ; // try to interexchange elements from the left and from the right while ( FirstLoopVariable <= SecondLoopVariable ) { while( ArrayOfValues[FirstLoopVariable] < CurrentValue ) { FirstLoopVariable = FirstLoopVariable + 1; } while ( ArrayOfValues[SecondLoopVariable] > CurrentValue ) { SecondLoopVariable = SecondLoopVariable - 1; } if ( FirstLoopVariable <= SecondLoopVariable ) { // Interexchange ArrayOfValues[i] and ArrayOfValues[j] HelpVariable = ArrayOfValues[FirstLoopVariable] ; ArrayOfValues[FirstLoopVariable] = ArrayOfValues[SecondLoopVariable] ; ArrayOfValues[SecondLoopVariable] = HelpVariable ; FirstLoopVariable = FirstLoopVariable + 1 ; SecondLoopVariable = SecondLoopVariable - 1 ; } } // Recursive call for both subsections if ( LeftBound < SecondLoopVariable ) { Quicksort( LeftBound , SecondLoopVariable , ArrayOfValues ); } if ( FirstLoopVariable < RightBound ) { Quicksort( FirstLoopVariable , RightBound , ArrayOfValues ); } }
void read(char name [], long int amount, char out []) { FILE *file; printf("%s", name); if (fopen_s(&file, name, "r")){ printf("\nCant find ", "%s", name, "file\n"); } long int array[250000]; fopen_s(&file, name, "r"); for (int i = 0; i < amount; i++) { fscanf_s(file, "%d", &array[i]); } fclose(file); // Программа сортировки// double start = clock(); //Начало отсчета Quicksort(0, amount - 1, array); double timework = (clock() - start) / CLOCKS_PER_SEC; // Остановка отсчета времени // вывод времени printf("\n"); printf("%.4lf", timework); printf("\n"); // вывод в файл// file = nullptr; fopen_s(&file, out, "w"); for (int i = 0; i < amount; i++) { fprintf(file, "%d", array[i]); fprintf(file, " "); } fclose(file); }
bool shrink(__int64_t n, int last) { int select = 10; int idx = 0; for(int i = 0; i < last - 1; ++i) { if(digit[i] > digit[last - 1]) { if(digit[i] < select) { select = digit[i]; idx = i; } } } if(select == 10) return false; digit[idx] = digit[last - 1]; digit[last - 1] = select; Quicksort(digit, 0, last - 2, SORT_LARGE_SMALL); return true; }
void Quicksort(CaseNo Fp, CaseNo Lp, Attribute Att) /* --------- */ { CaseNo i, Middle, High; ContValue Thresh, Val; if ( Fp < Lp ) { Thresh = CVal(Case[(Fp+Lp) / 2], Att); /* Divide cases into three groups: Fp .. Middle-1: values < Thresh Middle .. High: values = Thresh High+1 .. Lp: values > Thresh */ for ( Middle = Fp ; CVal(Case[Middle], Att) < Thresh ; Middle++ ) ; for ( High = Lp ; CVal(Case[High], Att) > Thresh ; High-- ) ; for ( i = Middle ; i <= High ; ) { if ( (Val = CVal(Case[i], Att)) < Thresh ) { Swap(Middle, i); Middle++; i++; } else if ( Val > Thresh ) { Swap(High, i); High--; } else { i++; } } /* Sort the first and third groups */ Quicksort(Fp, Middle-1, Att); Quicksort(High+1, Lp, Att); } }
void RunQuickSort(void) { int to_partition[] = {2, 1, 3, 7, 1, 3, 6, 4, 8, 3, 4, 1}; int size = sizeof(to_partition) / sizeof(int); PrintArray(to_partition, size); Quicksort(to_partition, 0, size); PrintArray(to_partition, size); }
void main() { printf("Enter positions (max 10) : "); int a[10]={0,0},i; for(i=0;i<10;i++) scanf("%d",&a[i]); Quicksort(a,0,9); closestpair(a,10); }
void Quicksort( SWIFT_Array<SWIFT_Real>& vals, SWIFT_Array<SWIFT_BV*>& leaves, int p, int r ) { if( p < r ) { // Compute a random element to use as the pivot int rn = (int) ((SWIFT_Real)(r-p+1) * drand48()) + p; int i = p-1; int j = r+1; SWIFT_Real x = vals[rn]; SWIFT_Real tr; SWIFT_BV* tp = leaves[rn]; // Swap the random element into the first position vals[rn] = vals[p]; vals[p] = x; leaves[rn] = leaves[p]; leaves[p] = tp; while( true ) { j--; while( vals[j] > x ) { j--; } i++; while( vals[i] < x ) { i++; } if( i < j ) { tr = vals[i]; vals[i] = vals[j]; vals[j] = tr; tp = leaves[i]; leaves[i] = leaves[j]; leaves[j] = tp; } else { break; } } Quicksort( vals, leaves, p, j ); Quicksort( vals, leaves, j+1, r ); } }
int geraTemporarios(FILE *f) { int i; char idTempFileName[10]; char tempFileName[20]; FILE *temp; // apontador para criar os arquivos temporários int fileCounter = 0; // conta quantos arquivos temporarios foram gerados char **ordenacao; // vetor para ordenar os floats lidos em memoria interna // Aloca matriz de caracteres para ordenação ordenacao = (char**) malloc(sizeof(char*) * FLOATS_MAX_READ); for (i = 0; i < FLOATS_MAX_READ; i += 1) { ordenacao[i] = (char*) malloc(sizeof(char) * FLOATS_MAX_LENGTH); strcpy(ordenacao[i], "-1.\0"); } while (!feof(f)) { // Lê quantidade do arquivo de entrada para memória for (i = 0; i < FLOATS_MAX_READ; i += 1) strcpy(ordenacao[i], "-1.\0"); for (i = 0; i < FLOATS_MAX_READ; i += 1) { if (feof(f)) break; fscanf(f, "%s", ordenacao[i]); } fileCounter += 1; // Dados em memória interna Quicksort(ordenacao, i); // Grava arquivo temporário strcpy(tempFileName, ""); sprintf(idTempFileName, "%d", fileCounter); strcat(tempFileName, "temp_"); strcat(tempFileName, idTempFileName); temp = fopen(tempFileName, "w"); for (i = 0; i < FLOATS_MAX_READ; i += 1) if (strcmp(ordenacao[i], "-1.") != 0) fprintf(temp, "%s\n", ordenacao[i]); fclose(temp); } // Libera memória interna for (i = 0; i < FLOATS_MAX_READ; i += 1) free(ordenacao[i]); free(ordenacao); return fileCounter; }
void Quicksort(int begin, long int end, long int s []){ long int middle = s[(begin + end) / 2]; long int i = begin; long int j = end; while (i < j) { while (s[i] < middle) ++i; while (s[j] > middle) --j; if (i <= j) { if (i < j) change(i, j, s); ++i; --j; } } if (i < end) Quicksort(i, end, s); if (j > begin) Quicksort(begin, j, s); }
void driver( enum sort atype, int *array, int elements, int random, int delay_factor ) { switch( atype ) { /* 所有排序算法 */ case all : /* 冒泡排序 */ case bubble : Setscreen( array, elements, random ); gprintf( &xaxis, &yaxis, *(sorts + bubble) ); Bubble( array, elements, delay_factor ); if ( atype != all ) break; else delay( 1350 ); /* 延迟交换排序 */ case delayed: Setscreen( array, elements, random ); gprintf( &xaxis, &yaxis, *(sorts + delayed) ); Delayed( array, elements, delay_factor ); if ( atype != all ) break; else delay( 1350 ); /* 希尔排序 */ case shell : Setscreen( array, elements, random ); gprintf( &xaxis, &yaxis, *(sorts + shell )); Shell( array, elements, delay_factor ); if ( atype != all ) break; else delay( 1350 ); /* Metzner希尔排序 */ case shell_metzner: Setscreen( array, elements, random ); gprintf( &xaxis, &yaxis, *(sorts + shell_metzner) ); Shell_Metzner( array, elements, delay_factor ); if ( atype != all ) break; else delay( 1350 ); /* 快速排序 */ case quick : Setscreen( array, elements, random ); gprintf( &xaxis, &yaxis, *(sorts + quick) ); Quicksort( array, 0, elements - 1, delay_factor ); if ( atype != all ) break; else delay( 1350 ); /* 插入排序 */ case insertion: Setscreen( array, elements, random ); gprintf( &xaxis, &yaxis, *(sorts + insertion) ); Insertion( array, elements, delay_factor ); if ( atype != all ) break; else delay( 1350 ); /* 停止 */ case stop: default:; } }
int main() { // Sorting array with 100 values already sorted low to high // with Selection Sort int SIZE_HUNDRED = 100; int testArray[SIZE_HUNDRED]; int testArray2[SIZE_HUNDRED]; int testArrayRandom[SIZE_HUNDRED]; int SIZE_THOUSAND = 1000; int testArrayThousand[SIZE_THOUSAND]; int testArrayThousand2[SIZE_THOUSAND]; int testArrayThousandRandom[SIZE_THOUSAND]; InitializeArrays( testArray, testArray2, testArrayRandom,testArrayThousand, testArrayThousand2, testArrayThousandRandom); int nA = sizeof(testArray)/sizeof(aType); cout << "nA: " << nA << endl; cout << "Initial array contents:" << endl; PrintArray( testArray, nA ); // cout << "Sorting with merge sort." << endl; // Mergesort( testArray, 0, nA-1 ); //cout << "Final array contents:" << endl; //PrintArray( testArrayThousandRandom, nA ); InitializeArrays( testArray, testArray2, testArrayRandom,testArrayThousand, testArrayThousand2, testArrayThousandRandom); cout << "Sorting with quick sort." << endl; Quicksort( testArray, 0, nA-1 ); cout << "Final array contents:" << endl; PrintArray( testArray, nA ); InitializeArrays( testArray, testArray2, testArrayRandom,testArrayThousand, testArrayThousand2, testArrayThousandRandom); cout << "Sorting with selection sort." << endl; SelectionSort( testArray, nA ); cout << "Final array contents:" << endl; PrintArray( testArray, nA ); // Sorting array with 100 values already sorted high to low // with selection sort int nB = sizeof(testArray2)/sizeof(aType); InitializeArrays( testArray, testArray2, testArrayRandom,testArrayThousand, testArrayThousand2, testArrayThousandRandom); cout << "nB: " << nB << endl; cout << "Initial array contents:" << endl; PrintArray( testArray2, nB ); //cout << "Sorting with merge sort." << endl; //Mergesort( testArray2, 0, nB-1 ); // cout << "Final array contents:" << endl; // PrintArray( testArray2, nB ); InitializeArrays( testArray, testArray2, testArrayRandom,testArrayThousand, testArrayThousand2, testArrayThousandRandom); cout << "Sorting with quick sort." << endl; Quicksort( testArray2, 0, nB-1 ); cout << "Final array contents:" << endl; PrintArray( testArray2, nB ); InitializeArrays( testArray, testArray2, testArrayRandom,testArrayThousand, testArrayThousand2, testArrayThousandRandom); cout << "Sorting with selection sort." << endl; SelectionSort( testArray2, nB ); cout << "Final array contents:" << endl; PrintArray( testArray2, nB ); // Sorting array with 100 random values int nE = sizeof(testArrayRandom)/sizeof(aType); InitializeArrays( testArray, testArray2, testArrayRandom,testArrayThousand, testArrayThousand2, testArrayThousandRandom); cout << "nE: " << nE << endl; cout << "Initial array contents:" << endl; PrintArray( testArrayRandom, nE ); //cout << "Sorting with merge sort." << endl; //Mergesort( testArrayRandom, 0, nE-1 ); // cout << "Final array contents:" << endl; // PrintArray( testArrayRandom, nE ); InitializeArrays( testArray, testArray2, testArrayRandom,testArrayThousand, testArrayThousand2, testArrayThousandRandom); cout << "Sorting with quick sort." << endl; Quicksort( testArrayRandom, 0, nE-1 ); cout << "Final array contents:" << endl; PrintArray( testArrayRandom, nE ); InitializeArrays( testArray, testArray2, testArrayRandom,testArrayThousand, testArrayThousand2, testArrayThousandRandom); cout << "Sorting with selection sort." << endl; SelectionSort( testArrayRandom, nE ); cout << "Final array contents:" << endl; PrintArray( testArrayRandom, nE ); // Sorting array with 1000 values already sorted low to high // with Selection Sort int nC = sizeof(testArrayThousand)/sizeof(aType); InitializeArrays( testArray, testArray2, testArrayRandom,testArrayThousand, testArrayThousand2, testArrayThousandRandom); cout << "nC: " << nC << endl; cout << "Initial array contents:" << endl; PrintArray( testArrayThousand, nC ); //cout << "Sorting with merge sort." << endl; //Mergesort( testArrayThousand, 0, nC-1 ); // cout << "Final array contents:" << endl; // PrintArray( testArrayThousand, nC ); InitializeArrays( testArray, testArray2, testArrayRandom,testArrayThousand, testArrayThousand2, testArrayThousandRandom); cout << "Sorting with quick sort." << endl; Quicksort( testArrayThousand, 0, nC-1 ); cout << "Final array contents:" << endl; PrintArray( testArrayThousand, nC ); InitializeArrays( testArray, testArray2, testArrayRandom,testArrayThousand, testArrayThousand2, testArrayThousandRandom); cout << "Sorting with Selection sort. " << endl; SelectionSort( testArrayThousand, nC ); cout << "Final array contents:" << endl; PrintArray( testArrayThousand, nC ); // Sorting array with 1000 values already sorted low to high // with Selection Sort int nD = sizeof(testArrayThousand2)/sizeof(aType); InitializeArrays( testArray, testArray2, testArrayRandom,testArrayThousand, testArrayThousand2, testArrayThousandRandom); cout << "nD: " << nD << endl; cout << "Initial array contents:" << endl; PrintArray( testArrayThousand2, nD ); //cout << "Sorting with merge sort." << endl; //Mergesort( testArrayThousand2, 0, nD-1 ); // cout << "Final array contents:" << endl; // PrintArray( testArrayThousand2, nD ); InitializeArrays( testArray, testArray2, testArrayRandom,testArrayThousand, testArrayThousand2, testArrayThousandRandom); cout << "Sorting with quick sort." << endl; Quicksort( testArrayThousand2, 0, nD-1 ); cout << "Final array contents:" << endl; PrintArray( testArrayThousand2, nD ); InitializeArrays( testArray, testArray2, testArrayRandom,testArrayThousand, testArrayThousand2, testArrayThousandRandom); cout << "Sorting with selection sort." << endl; SelectionSort( testArrayThousand2, nD ); cout << "Final array contents:" << endl; PrintArray( testArrayThousand2, nD ); // Sorting array with 1000 random values int nF = sizeof(testArrayThousandRandom)/sizeof(aType); InitializeArrays( testArray, testArray2, testArrayRandom,testArrayThousand, testArrayThousand2, testArrayThousandRandom); cout << "nF: " << nF << endl; cout << "Initial array contents:" << endl; PrintArray( testArrayThousandRandom, nF ); //cout << "Sorting with merge sort." << endl; //Mergesort( testArrayThousandRandom, 0, nF-1 ); // cout << "Final array contents:" << endl; // PrintArray( testArrayThousandRandom, nF ); cout << "Final array contents:" << endl; PrintArray( testArrayThousandRandom, nF ); InitializeArrays( testArray, testArray2, testArrayRandom,testArrayThousand, testArrayThousand2, testArrayThousandRandom); cout << "Sorting with quick sort." << endl; Quicksort( testArrayThousandRandom, 0, nF-1 ); cout << "Final array contents:" << endl; PrintArray( testArrayThousandRandom, nF ); InitializeArrays( testArray, testArray2, testArrayRandom,testArrayThousand, testArrayThousand2, testArrayThousandRandom); cout << "Sorting with selection sort." << endl; SelectionSort( testArrayThousandRandom, nF ); cout << "Final array contents:" << endl; PrintArray( testArrayThousandRandom, nF ); /* aType testArray[] = { 7, 13, 1, 3, 10, 5, 2, 4 }; int nA = sizeof(testArray)/sizeof(aType); cout << "nA: " << nA << endl; cout << "Initial array contents:" << endl; PrintArray( testArray, nA ); SelectionSort( testArray, nA ); cout << "Final array contents:" << endl; PrintArray( testArray, nA ); */ return 0; }
void main() { Seqlist S; int i; char ch1,ch2; printf("请输入10个待排序数据:(每个数据间用空格隔开)\n"); for(i=1; i<=n; i++) scanf("%d",&S[i].key); ch1='y'; while (ch1=='y' || ch1=='Y') { printf("*****************菜单***********************\n"); printf("请选择下列*作:\n"); printf("1------------------更新待排序数据-----------\n"); printf("2------------------直接插入排序-------------\n"); printf("3------------------冒泡排序-----------------\n"); printf("4------------------快速排序-----------------\n"); printf("5------------------直接选择排序-------------\n"); printf("6------------------堆排序-------------------\n"); printf("7------------------归并排序-----------------\n"); printf("8------------------基数排序-----------------\n"); printf("9------------------退出---------------------\n"); printf("请选择*作类别(1-9):"); scanf("\n%c",&ch2); switch (ch2) { case '1': printf("请输入更新待排序数据:\n"); for (i=1; i<=n; i++) scanf ("%d",&S[i].key); break; case '2': printf("请输入要输出第几趟结果:"); scanf("\n%d",&m); for (i=1; i<=n; i++) R[i].key=S[i].key; Insertsort(); break; case '3': printf("请输入要输出第几趟结果:"); scanf("\n%d",&m); for (i=1; i<n+1; i++) R[i].key=S[i].key; Bubblesort(); break; case '4': printf("请输入要输出第几趟结果:"); scanf("\n%d",&m); for (i=1; i<n+1; i++) R[i].key=S[i].key; num=0; Quicksort(1,n); break; case '5': printf("请输入要输出第几趟结果:"); scanf("\n%d",&m); for (i=1; i<n+1; i++) R[i].key=S[i].key; Selectsort(); break; case '6': printf("请输入要输出第几趟结果:"); scanf("\n%d",&m); for (i=1; i<n+1; i++) R[i].key=S[i].key; Heapsort(); break; case '7': printf("请输入要输出第几趟结果:"); scanf("\n%d",&m); for (i=1; i<n+1; i++) R[i].key=S[i].key; Mergesort(); break; case '8': printf("请输入要输出第几趟结果:"); scanf("\n%d",&m); for (i=0; i<n; i++) R[i].key=S[i+1].key; Radixsort(); break; case '9': ch1='n'; break; default: ch1='n'; } } }
void quicksort(Itr begin, Itr end) { Quicksort().sort(begin, end); }
double Dim::computeStep(Segment *t){ float** data; static bool first=false; static bool xflg=false; static bool yflg=false; static bool zflg=false; static int id1=0; static double correctOutput; static double correctOutputx = -1; static double correctOutputy = -1; static double correctOutputz = -1; int i; //defined a new variable to keep track of new neurons in case of multiple files. sri 05/10/2010 static const char* nameorig = t->getNeuronName(); const char* nametmp = t->getNeuronName(); //whenever the neuron changes all the flags for computing fill are reset. For each neuron and each function only once fill is computed. sri 05/10/2010. if(strncmp(nameorig,nametmp,strlen(nameorig))!=0){ nameorig = t->getNeuronName(); xflg = false;yflg = false; zflg = false; } if(strncmp(nameorig,nametmp,strlen(nameorig))==0 && (( x==1 && xflg == false) || (y==1 && yflg == false) || (z==1 && zflg == false))){ while(t->getId()!=1){ t = t->getPrev(); } id1=t->getId(); if(x==1){ setName("Width"); xflg=true; } else if(y==1){ setName("Height"); yflg=true; }else if(z==1){ zflg=true; setName("Depth"); } //count segment int seg=0; seg=countSegment(t); //cerr<<"first seg:"<<seg<<"\n"; data=matrix(seg,2); for(i=1;i<=seg;i++) for(int j=1;j<=2;j++){ data[i][j]=0; } //fills the data array with X or Y or Z coordinates fill(t,data); Quicksort(data,1,seg); //add the smallest element to the array to have all point positive float bias=data[1][1]; for( i=1;i<=seg;i++){ //subtracting the min value from all the values data[i][1]-=bias; } //get total length double tot=0; for( i=1;i<=seg;i++) tot+=data[i][2]; //get only 2.5% of total length int sum =tot; percent = 0.025; tot*=percent; //to remove 2.5% of data from leftmost end double tot_left=0; for( i=1;(i<=seg && tot>tot_left);i++) tot_left+=data[i][2]; if(i>seg) i=seg; double min=data[i][1]; //to remove 2.5% of data from rightmost end double tot_right= 0; for(i=seg;(i>=1 && tot>tot_right);i--) tot_right+=data[i][2]; if(i<1) i=1; double max=data[i][1]; free_matrix(data,seg,2); correctOutput=max-min; if(x==1){ correctOutputx=correctOutput;return correctOutput; } else if(y==1){ correctOutputy=correctOutput;return correctOutput; }else if(z==1){ correctOutputz=correctOutput;return correctOutput; } return correctOutput; } else{ if(x==1){ return correctOutputx; } else if(y==1){ return correctOutputy; }else if(z==1){ return correctOutputz; } } return VOID; }
int main(int argc, char *argv[]) { int* inputArray; //the matrix int* outputArray; int* finalArray; int rank, size, i, j, chunksize, k, n, isEven; pid_t mypid; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); n = 40000; //determines the size of the inputArray and vector inputArray = (int *) calloc(n, sizeof(int )); //create a 1 dimension inputArray of length n for vector outputArray = (int *) calloc(n, sizeof(int )); //create a 1 dimension inputArray of length n for vector finalArray = (int *) calloc(n, sizeof(int )); //create a 1 dimension inputArray of length n for vector chunksize = n/size; if(!rank) { printf("n is %d and chunksize is %d\n",n , chunksize); srand (time(NULL)); //fill inputArray with random ints for(i = 0; i<n; i++) { inputArray[i] = rand() % 100 + 1; //printf("%d ", inputArray[i]); } //printf("\n"); } for(k = 0; k < (n/2); k++) { if(!rank) { if(k%2==0) { MPI_Scatter(inputArray, chunksize, MPI_INT, outputArray, chunksize, MPI_INT, 0, MPI_COMM_WORLD); Quicksort(outputArray, 0, chunksize - 1); //BubbleSort(outputArray, 0, chunksize); MPI_Gather(outputArray, chunksize, MPI_INT, finalArray, chunksize, MPI_INT, 0, MPI_COMM_WORLD); } else{ MPI_Scatter(&(inputArray[1]), chunksize, MPI_INT, outputArray, chunksize, MPI_INT, 0, MPI_COMM_WORLD); //BubbleSort(outputArray, 0, chunksize); Quicksort(outputArray, 0, chunksize - 1); MPI_Gather(outputArray, chunksize, MPI_INT, &(finalArray[1]), chunksize, MPI_INT, 0, MPI_COMM_WORLD); finalArray[0] = inputArray[0]; finalArray[n-1] = inputArray[n-1]; inputArray = finalArray; } } else { for(k = 0; k < (n/2); k++) { if(k%2==0) { MPI_Scatter(inputArray, chunksize, MPI_INT, outputArray, chunksize, MPI_INT, 0, MPI_COMM_WORLD); Quicksort(outputArray, 0, chunksize - 1); //BubbleSort(outputArray, 0, chunksize); MPI_Gather(outputArray, chunksize, MPI_INT, finalArray, chunksize, MPI_INT, 0, MPI_COMM_WORLD); isEven = 0; } else { MPI_Scatter(&(inputArray[1]), chunksize, MPI_INT, outputArray, chunksize, MPI_INT, 0, MPI_COMM_WORLD); Quicksort(outputArray, 0, chunksize - 1); if(rank != size - 1) Quicksort(outputArray, 0, chunksize - 1); //BubbleSort(outputArray, 0, chunksize); MPI_Gather(outputArray, chunksize, MPI_INT, &(finalArray[1]), chunksize, MPI_INT, 0, MPI_COMM_WORLD); isEven = 1; } } } } if(!rank) { //for(i = 0; i < n; i++) // printf("%d ", finalArray[i]); // printf("\n"); } MPI_Finalize(); return 0; }
int main(int argc, char **argv) { double **R, **AV, **ML, **subML, **MR, **subMR, **MAtil,**subM, **M,**Atil, **AtilT, **subTrans,**L, **subFro, **Dn, **matrizSwap; double *mediana; double RMSE[]={0.0,0.0}, erro=0.0, dblSwap=0.0; int intSwap=0; int subMatrizD = 0, xSubMatriz = 0, ySubMatriz = 0; int cont = 0, // Contadores contM = 0, contL = 0, contC = 0, contSC = 0, contSL = 0, contD1 = 0, contD2 = 0, contMC = 0, contML = 0, contI = 0; FILE *ARQUIVO; int DEBUG = 0, // Padrao: Sem Debug ... LTIPO = 0, // Tipo inicial da Matriz L ( Identidade ou Randomica ) ... MMEDIA = 0, // Tipo de Media ( media ou mediana ) ... TIPODD = 0, // Tipo de Dado Salvo no Arquivo 4r, Padrao: Duplo ... DUPLO = 0, INTEIRO = 1; system("clear"); // Validacao dos argumentos ... if ( argc < 7 ) { printf("USO: gpca.bin arquivo.de.entrada.bmp arquivo.de.saida.4r D X Y TipoMedia tipoL TipoDeDado <debug>\n\n"); printf("-----------------------------------------------------------------------------------------\n"); printf("Parametros\n"); printf("-----------------------------------------------------------------------------------------\n"); printf("E :\tO erro minimo do RMSE (Ex: 0.05)\n"); printf("D :\tTamanho do Elemento D, para a compressao.\n"); printf("X :\tLargura da SubMatriz.\n"); printf("Y :\tAltura da SubMatriz.\n"); printf("Media :\tMetodo de calculo da media inicial (media | mediana). \n"); printf("TipoL :\tTipo de matriz inicial L que sera utilizada (identidade | randomica).\n"); printf("Tipo de Dado :\tFormato como o arquivo sera salvo ( duplo | inteiro ).\n"); printf("-----------------------------------------------------------------------------------------\n\n"); printf("Exemplo: ./gpca.bin matrix2.bmp imagem.4r 0.05 2 3 3 media identidade inteiro debug\n\n"); exit(1); } erro = atof(argv[3]); // Erro subMatrizD = atoi(argv[4]); // Tamanho dos Ds xSubMatriz = atoi(argv[5]); // Larguca da SubMatriz ySubMatriz = atoi(argv[6]); // Altura da SubMatriz if ( strcmp(argv[7], "mediana") == 0 ) MMEDIA = 1; if ( strcmp(argv[8], "randomica") == 0 ) LTIPO = 1; if ( strcmp(argv[9], "inteiro") == 0 ) TIPODD = INTEIRO; if ( argc == 11 ) if ( strcmp(argv[10], "debug") == 0 ) DEBUG = 1; // Carga da Imagem na Matriz ... printf("\nCarga da Imagem na Matriz ... " ); mtxImage = load_image_to_matrix(argv[1], &mtxImageWidth, &mtxImageHeight); if ( mtxImage == NULL ) { printf("Erro durante a carga da matriz ...\n\n"); exit(99); } // Abre arquivo de saida dos dados ... if ( DEBUG ) { if ( ( ARQUIVO = fopen(argv[2],"w")) == NULL ) { printf("Erro abrindo arquivo %s\n", argv[2]); exit(1); } } else { if ( ( ARQUIVO = fopen(argv[2],"wb")) == NULL ) { printf("Erro abrindo arquivo %s\n", argv[2]); exit(1); } } // Descobre a largura da Matriz if ( mtxImageWidth == 0 ){ mtxWidth = 0; mtxFwidth = 0; } else { mtxWidth = (int)mtxImageWidth; mtxFwidth = mtxWidth - xSubMatriz; mtxWidth /= xSubMatriz; } // Descobre a altura da Matriz if ( mtxImageHeight == 0 ) { mtxHeight = 0; mtxFheight = 0; } else { mtxHeight = (int)mtxImageHeight; mtxFheight = mtxHeight - ySubMatriz; mtxHeight /= ySubMatriz; } // Alocacao de Matrizes ... printf("\nAlocacao das matrizes ...\n"); M = AlocarMatriz(xSubMatriz, ySubMatriz); Atil = AlocarMatriz((int)mtxImageWidth,(int)mtxImageHeight); AtilT = AlocarMatriz((int)mtxImageWidth,(int)mtxImageHeight); L = AlocarMatriz(subMatrizD, xSubMatriz); R = AlocarMatriz(subMatrizD, ySubMatriz); AV = AlocarMatriz(xSubMatriz, ySubMatriz); MR = AlocarMatriz(xSubMatriz, ySubMatriz); ML = AlocarMatriz(xSubMatriz, ySubMatriz); subM = AlocarMatriz(xSubMatriz, ySubMatriz); matrizSwap = AlocarMatriz(xSubMatriz, ySubMatriz); mediana = malloc((mtxFwidth * mtxFheight) * sizeof(double)); // ToDo o espaco alocado e maior do que o necessario, // pois deve ser dividido pelo tamanho das submatrizes. printf("\nMedia das submatrizes ...\n"); if ( DEBUG ) { fprintf(ARQUIVO,"\n= = = = =[ DADOS ]= = = = = = = = = = = = = = = = = = = = = = = = =\n\n"); fprintf(ARQUIVO,"Largura : %4d\n", mtxImageWidth); fprintf(ARQUIVO,"Altura : %4d\n\n", mtxImageHeight); fprintf(ARQUIVO,"Matriz A: "); for( contL=0; contL<(int)mtxImageHeight;contL++){ fprintf(ARQUIVO,"|"); for ( contC=0; contC<(int)mtxImageWidth; contC++ ) fprintf(ARQUIVO,"%4d ", (int)mtxImage[contL][contC]); fprintf(ARQUIVO,"|\n "); } fprintf(ARQUIVO,"\n"); } else { fprintf(ARQUIVO, "%s", "4R"); fwrite(&mtxImageWidth, 4, 1, ARQUIVO); // Largura da Imagem ... fwrite(&mtxImageHeight, 4, 1, ARQUIVO); // Altura da Imagem ... fwrite(&subMatrizD, 4, 1, ARQUIVO); // Tamanho do D ... fwrite(&xSubMatriz, 4, 1, ARQUIVO); // Largura SubMatriz ... fwrite(&ySubMatriz, 4, 1, ARQUIVO); // Altura SubMatriz ... fwrite(&TIPODD, 4, 1, ARQUIVO); // Tipo do Dado Salvo ... } if ( MMEDIA == 0 ) { // Calcula a Media das SubMatrizes ... for( contL=0; contL<ySubMatriz;contL++){ for ( contC=0; contC<xSubMatriz; contC++ ){ M[contL][contC]=0; for (contMC=0;contMC<= mtxFwidth;contMC +=xSubMatriz){ for ( contML=0;contML<=mtxFheight;contML +=ySubMatriz){ M[contL][contC] += mtxImage[contL+contML][contC+contMC]; } } M[contL][contC] /= mtxWidth*mtxHeight; dblSwap = M[contL][contC]; if ( !DEBUG ) { fwrite(&dblSwap, 8, 1, ARQUIVO); } } } } else { // Calcula a Mediana das SubMatrizes ... for( contL=0; contL<ySubMatriz;contL++){ for ( contC=0; contC<xSubMatriz; contC++ ){ M[contL][contC]=0; cont = 0; mediana[cont] = 0.0; for (contMC=0;contMC<= mtxFwidth;contMC +=xSubMatriz){ for ( contML=0;contML<=mtxFheight;contML +=ySubMatriz){ mediana[cont] = mtxImage[contL+contML][contC+contMC]; cont++; } } Quicksort(mediana,0,cont-1); // cont -1 por que e o valor de todas as M[contL][contC] = CalcMediana(mediana,cont-1); // iteracoes -1 por que comeca do zero... dblSwap = M[contL][contC]; if ( !DEBUG ) { fwrite(&dblSwap, 8, 1, ARQUIVO); } } } } if ( DEBUG ) { fprintf(ARQUIVO,"\nMatriz M: "); for( contL=0; contL<(int)ySubMatriz;contL++){ fprintf(ARQUIVO,"|"); for ( contC=0; contC<(int)xSubMatriz; contC++ ) fprintf(ARQUIVO,"%4d ", (int)M[contL][contC]); fprintf(ARQUIVO,"|\n "); } fprintf(ARQUIVO,"\n"); } // Calcula a Matriz Atil ... printf("\nMatrizes Atil ..."); contSL = contSC = 0; for( contC=0; contC<(int)mtxImageWidth;contC++){ for ( contL=0; contL<(int)mtxImageHeight; contL++ ) { Atil[contL][contC] = mtxImage[contL][contC] - M[contSL][contSC]; contSL++; if (contSL >= ySubMatriz) contSL=0; } contSC++; if (contSC >= xSubMatriz) contSC=0; } if ( DEBUG ) { fprintf(ARQUIVO,"\nMatriz Atil: "); for( contL=0; contL<(int)mtxImageHeight;contL++){ fprintf(ARQUIVO,"|"); for ( contC=0; contC<(int)mtxImageWidth; contC++ ) fprintf(ARQUIVO,"%4d ", (int)Atil[contL][contC]); fprintf(ARQUIVO,"|\n "); } fprintf(ARQUIVO,"\n"); } // Obtem Matriz Tranposta da Atil printf("\nMatriz Tranposta A~ ..."); cont = contSL = contSC = 0; for ( contML=0;contML<mtxHeight;contML++){ for ( contMC=0;contMC<mtxWidth;contMC++){ subTrans = TransposicaoMatriz(ObterSubMatriz(Atil, xSubMatriz, ySubMatriz, contMC, contML), xSubMatriz, ySubMatriz); for (contC=0;contC<xSubMatriz;contC++){ for (contL=0;contL<ySubMatriz;contL++){ AtilT[contSL+cont][contSC]=subTrans[contL][contC]; contSL++; if ( contSL >= ySubMatriz ) contSL = 0 ; } if ( contSC < (int)mtxImageWidth - 1) { contSC++; } else { contSC= 0; cont += xSubMatriz; } } DesalocarMatriz(subTrans,xSubMatriz); } } if ( DEBUG ) { fprintf(ARQUIVO,"\nMatriz AtiT: "); for( contL=0; contL<(int)mtxImageHeight;contL++){ fprintf(ARQUIVO,"|"); for ( contC=0; contC<(int)mtxImageWidth; contC++ ) fprintf(ARQUIVO,"%4d ", (int)AtilT[contL][contC]); fprintf(ARQUIVO,"|\n "); } fprintf(ARQUIVO,"\n"); } // Inicializacao de L ... if ( LTIPO == 1 ) RandomizarMatriz(L, subMatrizD,ySubMatriz, 256); else L = RetornaMatrizIdentidade(ySubMatriz,subMatrizD); // Calculo do RMSE printf("\nExecutando Compressao (Calculo do RMSE) ...\n"); printf("Iteracao:\n"); if ( DEBUG ) fprintf(ARQUIVO,"Inicio do Loop para calculo do RMSE!\n\n"); do { contI++; printf("%d ...\n", contI); if ( DEBUG ) fprintf(ARQUIVO,"\nRMSE - Iteracao %03d\n\n", contI); RMSE[0] = RMSE[1]; RMSE[1] = 0.0; // Calculo de MR ... for (contC=0;contC<xSubMatriz;contC++) for (contL=0;contL<ySubMatriz;contL++) MR[contL][contC]=0.0; for (contML=0;contML<mtxHeight;contML++){ for (contMC=0;contMC<mtxWidth;contMC++){ subMR = ObterSubMatriz(AtilT, xSubMatriz, ySubMatriz, contMC, contML); subMR = MultiplicacaoMatriz('r',subMR, xSubMatriz, ySubMatriz,L,subMatrizD,xSubMatriz); // AtilT * Lo subMR = MultiplicacaoMatriz('r',subMR, subMatrizD, xSubMatriz,TransposicaoMatriz(L, subMatrizD, xSubMatriz), xSubMatriz, subMatrizD); // (AtilT * Lo ) * LoT subMR = MultiplicacaoMatriz('r',subMR, xSubMatriz, ySubMatriz,ObterSubMatriz(Atil, xSubMatriz, ySubMatriz, contMC, contML), xSubMatriz, ySubMatriz); // (AtilT * Lo * LoT) * Atil] for (contC=0;contC<xSubMatriz;contC++) for (contL=0;contL<ySubMatriz;contL++) MR[contL][contC]+=subMR[contL][contC]; DesalocarMatriz(subMR, ySubMatriz); } } if ( DEBUG ) { fprintf(ARQUIVO,"\n Matriz MR: "); for( contL=0; contL<(int)ySubMatriz;contL++){ fprintf(ARQUIVO,"|"); for ( contC=0; contC<(int)xSubMatriz; contC++ ) fprintf(ARQUIVO,"%10f ", MR[contL][contC]); fprintf(ARQUIVO,"|\n "); } fprintf(ARQUIVO,"\n"); } AutoVV(MR, R, AV, subMatrizD, ySubMatriz); if ( DEBUG ) { fprintf(ARQUIVO,"\n Matriz R: "); for( contL=0; contL<(int)xSubMatriz;contL++){ fprintf(ARQUIVO,"|"); for ( contC=0; contC<(int)subMatrizD; contC++ ) fprintf(ARQUIVO,"%10f ", R[contL][contC]); fprintf(ARQUIVO,"|\n "); } fprintf(ARQUIVO,"\n"); } // Calculo do ML for (contC=0;contC<xSubMatriz;contC++) // Prepara a matriz ML for (contL=0;contL<ySubMatriz;contL++) ML[contL][contC] = 0.0; for (contML=0;contML<mtxHeight;contML++){ for (contMC=0;contMC<mtxWidth;contMC++){ subML = ObterSubMatriz(Atil, xSubMatriz, ySubMatriz, contMC, contML); subML = MultiplicacaoMatriz('r',subML, xSubMatriz, ySubMatriz,R, subMatrizD, ySubMatriz); subML = MultiplicacaoMatriz('r',subML,subMatrizD , xSubMatriz,TransposicaoMatriz(R,subMatrizD , ySubMatriz), ySubMatriz, subMatrizD); subML = MultiplicacaoMatriz('r',subML, xSubMatriz, ySubMatriz,ObterSubMatriz(AtilT, xSubMatriz, ySubMatriz, contMC, contML), xSubMatriz, ySubMatriz); for (contC=0;contC<xSubMatriz;contC++) for (contL=0;contL<ySubMatriz;contL++) ML[contL][contC] += subML[contL][contC]; } } DesalocarMatriz(subML, xSubMatriz); if ( DEBUG ) { fprintf(ARQUIVO,"\n Matriz ML: "); for( contL=0; contL<(int)ySubMatriz;contL++){ fprintf(ARQUIVO,"|"); for ( contC=0; contC<(int)xSubMatriz; contC++ ) fprintf(ARQUIVO,"%10f ", ML[contL][contC]); fprintf(ARQUIVO,"|\n "); } fprintf(ARQUIVO,"\n"); } AutoVV(ML, L, AV, subMatrizD, xSubMatriz); if ( DEBUG ) { fprintf(ARQUIVO,"\n Matriz L: "); for( contL=0; contL<(int)ySubMatriz;contL++){ fprintf(ARQUIVO,"|"); for ( contC=0; contC<(int)subMatrizD; contC++ ) fprintf(ARQUIVO,"%10f ", L[contL][contC]); fprintf(ARQUIVO,"|\n "); } fprintf(ARQUIVO,"\n"); } for ( contML=0;contML<mtxHeight;contML++){ for (contMC=0;contMC<mtxWidth;contMC++){ subFro = MultiplicacaoMatriz('n', L, subMatrizD, xSubMatriz, TransposicaoMatriz(L, subMatrizD, xSubMatriz), xSubMatriz, subMatrizD); // L * LT subFro = MultiplicacaoMatriz('r', subFro, xSubMatriz, ySubMatriz, ObterSubMatriz(Atil, xSubMatriz, ySubMatriz, contMC, contML), xSubMatriz, ySubMatriz); // ( L * LT ) * Atil subFro = MultiplicacaoMatriz('r', subFro, xSubMatriz, ySubMatriz, R, subMatrizD, ySubMatriz); // ( L * LT * Atil ) * R subFro = MultiplicacaoMatriz('r', subFro, subMatrizD, ySubMatriz, TransposicaoMatriz(R, subMatrizD, ySubMatriz), ySubMatriz, subMatrizD); // ( L * LT * Atil * R ) * RT subFro = SubtraiMatriz('r', subFro, ObterSubMatriz(Atil, xSubMatriz, ySubMatriz, contMC, contML), xSubMatriz, ySubMatriz); // Atil - ( L * LT * Atil * R * RT ) RMSE[1] += ModuloMatriz(subFro, xSubMatriz, ySubMatriz, 'f'); DesalocarMatriz(subFro, ySubMatriz); } } RMSE[1] /= mtxWidth * mtxHeight; if ( DEBUG ) fprintf(ARQUIVO,"\n Erro RMSE: %10.8f\n\n", fabs(RMSE[0] - RMSE[1])); } while ( fabs(RMSE[0] - RMSE[1]) > erro ); printf("\nTermino da Compressao. RMSE: %20.18f ...", fabs(RMSE[0] - RMSE[1])); printf("\nGravando dados no arquivo de saida ..."); if ( DEBUG ) fprintf(ARQUIVO,"\nR = {"); for ( contL=0;contL<ySubMatriz;contL++){ for ( contC=0;contC<subMatrizD;contC++){ if ( DEBUG ) { fprintf(ARQUIVO,"%10.4f",R[contL][contC]); if ( contC < subMatrizD - 1 ) fprintf(ARQUIVO,","); } else { dblSwap = R[contL][contC]; fwrite(&dblSwap, 8, 1, ARQUIVO); } } if ( DEBUG ) if ( contL < subMatrizD ) fprintf(ARQUIVO,";"); } if ( DEBUG ) { fprintf(ARQUIVO,"}"); fprintf(ARQUIVO,"\nL = {"); } for ( contL=0;contL<ySubMatriz;contL++){ for ( contC=0;contC<subMatrizD;contC++){ if ( DEBUG ) { fprintf(ARQUIVO,"%10.4f",L[contL][contC]); if ( contC < subMatrizD - 1 ) fprintf(ARQUIVO,","); } else { dblSwap = L[contL][contC]; fwrite(&dblSwap, 8, 1, ARQUIVO); } } if ( DEBUG ) if ( contL < subMatrizD ) fprintf(ARQUIVO,";"); } if ( DEBUG ) fprintf(ARQUIVO,"}"); cont=0; for (contML=0;contML<mtxHeight;contML++){ for (contMC=0;contMC<mtxWidth;contMC++){ cont++; Dn = MultiplicacaoMatriz('n', TransposicaoMatriz(L, subMatrizD, xSubMatriz), xSubMatriz, subMatrizD, ObterSubMatriz(Atil, xSubMatriz, ySubMatriz, contMC, contML), xSubMatriz, ySubMatriz); Dn = MultiplicacaoMatriz('r', Dn, xSubMatriz, subMatrizD, R, subMatrizD, ySubMatriz); // Erro ... verificar desalocacao desta matriz ... if ( DEBUG ) fprintf(ARQUIVO,"\nD = {"); for ( contL=0;contL<subMatrizD;contL++){ for ( contC=0;contC<subMatrizD;contC++){ if ( DEBUG ) { if ( TIPODD == DUPLO ) fprintf(ARQUIVO,"%10.4f",Dn[contL][contC]); else fprintf(ARQUIVO,"%10d",(int)(Dn[contL][contC] * 1000000.0)); if ( contC < 1 ) fprintf(ARQUIVO,","); } else { if ( TIPODD == DUPLO ) { dblSwap = Dn[contL][contC]; fwrite(&dblSwap, 8, 1, ARQUIVO); } else { intSwap = (int)(Dn[contL][contC] * 1000000.0); fwrite(&intSwap, 4, 1, ARQUIVO); } } } if ( DEBUG ) if ( contL < 1 ) fprintf(ARQUIVO,";"); } if ( DEBUG ) fprintf(ARQUIVO,"}"); } } fprintf(ARQUIVO,"\n\n"); fclose(ARQUIVO); printf("\n\nProcesso concluido ...\n\n\n"); DesalocarMatriz(MR, ySubMatriz); // Desaloca MR DesalocarMatriz(ML, xSubMatriz); // Desalocar ML // ToDo: Verificar erro na desalocacao destas submatrizes ... // DesalocarMatriz(AV, 2); // DesalocarMatriz(R, 2); // Desalocar R // DesalocarMatriz(L, 2); // Desalocar L DesalocarMatriz(M,xSubMatriz); // Desalocar M DesalocarMatriz(Atil,xSubMatriz); DesalocarMatriz(AtilT,ySubMatriz); exit(0); }