Jump to content
Sign in to follow this  

Como altero este metodo para que ordene bem?

Recommended Posts


Boas pessoal este metodo que criei nao está a ordenar bem porque nao ordena os laterais, em caso de empate..

public static int[] ordena(int[] soma, double[] media){

	int[] ordem = new int[soma.length];

	int aux1,aux2,aux3,trocas;
	double auxm;

	for(int j = 0; j < ordem.length; j++)
		ordem[j] = j;

	aux1= 0; aux2 = 0; aux3 = 0; auxm = 0; trocas = 0;

		trocas = 0;
		for(int i = 0; i < soma.length-1; i++){

		if(soma[i+1] > soma[i]){
			aux1 = ordem[i];
			ordem[i] = ordem[i+1];
			ordem[i+1] = aux1;

			aux2 = soma[i];
			soma[i] = soma[i+1];
			soma[i+1] = aux2;

			auxm = media[i];
			media[i] = media[i+1];
			media[i+1] = auxm;

			trocas = 1;

		if(soma[i+1] == soma[i]){
			aux3 = ordem[i];
			ordem[i] = ordem[i+1];
			ordem[i+1] = aux3;
	while(trocas == 1);

	return ordem;

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.