Help me sortarisma (metrisi sixnotitas)

Dimitris Mexis m65 at vivodinet.gr
Thu Jul 6 10:28:59 EEST 2006


Xero oti polloi pali tha poun alla to vala se allo simio kai den exo kai
poli megali adapokrisi, opote to anarto kai edo:

Exo to parakato kodika se poli genikes grammes.... Otan loipon ftaso
stin GroupBy kai grouparo tis times kai pao na anatheso opou freq[d] =
tmpFreq[d], simvenei oti to freq[d] pou thelo na pistevo oti adistixei sto
stocks[recordscapm].capm.grpprice, ehei ginei delete, ehei gini NULL, kai
meta oti to xanaxrisimopoio afova, kai eno to tmpFreq[d] eno metraei
apsoga (leme tora) tis sihnotites emfaniseis, paratiro oti se kapoies
times xoris na katalaveno giati, to freq[d] adistoixeitai me arnitiko
arithmo kai malista polles fores ena tixeo dekadiko.Oute kan to
-tmpFreq[d]. Den katalaveno giati...
Efharisto.

main(){
stocks[recordscapm].capm.price = new float[tRec];
stocks[recordscapm].capm.grpprice = new float[tRec];
stocks[recordscapm].capm.timebuy = new string[tRec];
stocks[recordscapm].capm.freq = new float[tRec];
	

FreqArrayCount( stocks[recordscapm].capm.grpprice, stocks[recordscapm].capm.freq, 
			stocks[recordscapm].capm.elements, 
			stocks[recordscapm].capm.grpelements );
			
			
}	

void FreqArrayCount( float *& matrix, float *& freq, size_t elements, size_t &grpelements ){
	size_t i, k, count;
	
	SortPrices( matrix, elements );

	for ( i = 0; i < elements; i++ ){
		count = 0;
		for ( k = 1; k < elements; k++ ){
			if ( (matrix[i] != NULL ) && ( matrix[k] != NULL ) ){
				if ( fabs( matrix[i] - matrix[k] ) <= PRECISION ){
					count++;
					freq[i] = count;
					}
				}
			}
		}
	
	GroupBy( matrix, freq, elements, grpelements );
}

void SortPrices( float *&array, size_t size){
	float min;int b;
	//This loop goes through the whole array

	for( int a = 0; a < size-1; a++ ){
		b = a;
		min = array[b];	//Get the current value
				//...and check if any of the rest numbers is lower
		for(int j = a+1; j<size; j++){
			if( array[j]< min ){
				b = j;
				min = array[b]; //...and if yes, then get it
			}
		}
		//Switch the values...
		array[b]=array[a];
		array[a]=min;
	}

void GroupBy( float *&matrix, float *&freq, size_t &elements, size_t &grpelements ){
	float tmpMatrix[elements];
	float tmpFreq[elements];
	int c = 0;
	int ii = 0;
	for ( int i = 0; i < elements; i++ ){
		tmpMatrix[c] = matrix[i];
		tmpFreq[c] = freq[i];
		if ( i < elements  )
			ii = i + 1;
			
		if ( !( fabs( matrix[ii] - matrix[i] ) <= PRECISION) )
			c+=1;
	}

	delete [] matrix;
	delete [] freq;
	matrix = NULL;
	freq = NULL;
	
	cout << "New elements :" << c << endl;
	
	matrix = new float[c];
	freq = new float[c];
	for ( int d = 1; d < c; d++ ){
	//We assign each value to the new array
		if ( ( tmpFreq[d] != NULL ) && ( tmpMatrix[d] != NULL ) && ( tmpFreq[d] !=0 ) ){
			matrix[d] = tmpMatrix[d];
			freq[d] = tmpFreq[d];
			}
	}
	grpelements = c;
	cout << "Finished grouping...." << endl;
}





More information about the Linux-greek-users mailing list