Bubble sort em ordem alfabética random

2 respostas
G

o vetor tem que receber letras random e depois fazer a ordenação bubble sort em ordem alfabetica se alguem souber me da uma ajuda por favor

2 Respostas

TerraSkilll

Que tipo de ajuda você precisa? Só postar o enunciado não é legal. Leia a referência clicando neste link.

Um tópico recente fala sobre ordenação BubbleSort: BubbleSort (Iniciante)

E há outros sobre geração de Strings aleatórias. Ex: GERADOR DE SENHA Alfanumerico

Abraço.

G

Até agora consegui isso

long inicioB;

long fim;

long resultado;

int quantidade = 1000;

Random random = new Random();

String vet[] = new String[quantidade];

String base[] = {“A, B, C, D, E, F, G, H, I, J, L,

M, N, O, P, Q, R, S, T, U, V, X, Z”};
for (int inicio = 0; inicio < vet.length; inicio++) {
        vet[inicio] = base[random.nextInt(base.length)];
    }
    
    for (int cel = 0; cel < vet.length; cel++) {
        System.out.println(vet[cel]);
    }
    inicioB = System.currentTimeMillis();
    bubbleSort(vet);
    fim = System.currentTimeMillis();
    resultado = (fim - inicioB);
    //System.out.printf("%.3f ms%n", (fim - inicio) / 1000d);
    txtTempoB.setText(txtTempoB.getText() + ((resultado) / 1000d) + " ms");
}                                      

/////////////////////////Buble///////////////

public static void bubbleSort(String[] tamanho) {
  

	for (int i = 0; i < tamanho.length - 1; i++) {
		for (int j = 0; j < tamanho.length - 1 - i; j++) {
			if(tamanho[j].compareTo(tamanho[ j+1 ])>0) { 
				String auxiliar = tamanho[j];
				tamanho[j] = tamanho[j + 1];
				tamanho[j + 1] = auxiliar;
			}
		}
	}
}

Mas gostaria que em vez de gerar uma letra gostaria que gerasse 15 letras randômica

Criado 4 de novembro de 2019
Ultima resposta 4 de nov. de 2019
Respostas 2
Participantes 2