Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public List<Pair<String, Integer>> a6_Ordena1(List<String> morses, String tipo,BST<Morse>bst) {
- List<Pair<String, Integer>> aux = new ArrayList<>();
- for (String s : morses) {
- Pair<String, Integer> p = a6_morseDecoder(s, tipo);
- if (p.getValue() != 0) {
- aux.add(p);
- }
- }
- a6_OrdenaTipo(aux);
- return aux;
- }
- private Pair<String, Integer> a6_morseDecoder(String morse, String tipo) {
- String chars[] = morse.split(" ");
- String palavra = "";
- int contador = 0;
- int j = 0;
- for (int i = 0; i < chars.length; i++) {
- char cod[];
- cod = chars[i].toCharArray();
- Morse c = a2_morseDecoder(bst.root, cod, j, chars[i]);
- if (c.getTipo().compareToIgnoreCase(tipo) == 0) {
- contador++;
- }
- palavra += c.getLetra();
- }
- Pair<String, Integer> p = new Pair<>("", 0);
- if (contador != 0) {
- p = new Pair<>(palavra, contador);
- }
- return p;
- }
- private void a6_OrdenaTipo(List<Pair<String, Integer>> ordenada) {
- System.out.println("ola");
- for (int i = 0; i < ordenada.size() - 1; i++) {
- for (int j = i+1; j < ordenada.size(); j++) {
- System.out.println("");
- if (ordenada.get(i).getValue() < ordenada.get(j).getValue()) {
- Pair<String, Integer> menor = ordenada.get(i);
- ordenada.set(i, ordenada.get(j));
- ordenada.set(j, menor);
- }
- }
- }
- }
- private Morse a2_morseDecoder(Node<Morse> node, char[] cod, int i, String aux) {
- if (aux == null) {
- return null;
- }
- if (aux.compareTo(node.getElement().getMorse()) == 0) {
- return node.getElement();
- }
- if (i < cod.length) {
- if (cod[i] == '.') {
- return a2_morseDecoder(node.getLeft(), cod, ++i, aux);
- } else {
- return a2_morseDecoder(node.getRight(), cod, ++i, aux);
- }
- }
- return new Morse("/", " ", "Espaço");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement