Λιγο βοήθεια με τη C

Dimitris Mexis m65 at vivodinet.gr
Thu Jun 1 23:26:56 EEST 2006


Exo ton parakato kodika, pistevo oti tha nai efkolo poli, se kapoion na to
trexi me ena gcc apla...
To provlima einai oti stelno loipon, mia matrix[] array stin sinartisi
selsort(), mou sortari tin array, pame kala, stelno meta tin matrix[]
array sto freq_array() kai pragmati petixeno na perno, poses times ehei
vrei...OMOS. Exo kolisi sto pos telika na paro mia struct(?), array(?),
list(? den xero kai STL ), me tis metavlites kai tin sixnotita apla pou
emfanizontai...diladi mia nea isos matrix, pou na leei oti telika to 1 to
de 1 , to 2 to vrike 3, klp klp, kai oxi 1,1,2,2,2,3,3,4 klp klp...
Prospatho na vgalo mia routina pou apla na mou epistrefi tin sixnotita
emfaniseis ton apotelesmaton tis matrix....(Me para poli apla logia)
:-) 
Efharisto!

void freq_array( double mtx[], int elements ){
//The mtx is a ghost of the matrix I transfer, VORSICHT!!!

	selsort( mtx, elements );

	int found = 0;
	
	cout << "...after!" << endl;
	for ( int i = 0; i < elements; i++ ){
		for ( int x = 0; x < elements; x++ ){
			if ( mtx[x] == mtx[i] ){
				found++;
				}
		}
		cout << "Found value :" << mtx[i] << ", times :" << found << endl;
		found = 0;
	}
}

//Selection Sort function
//Takes two parameters:
//int *array- the array with the numbers to be sorted
//int size- the size of the array
void selsort( double *array,int size){
	int 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;
	}
}

int main(int argc, char *argv[])
{
	double matrix[10];
	cout << "before..." << endl;
	for ( int i = 0; i < 10; i++ ){
		matrix[i] = 10 - i;
		matrix[3] = 3;
		matrix[4] = 3;
		matrix[1] = 2;
		matrix[0] = 0;
		cout << matrix[i] << endl;
		}
	freq_array( matrix, ( sizeof( matrix )/sizeof( matrix[0] ) ) );
	
	exit(0);
}





More information about the Linux-greek-users mailing list