Advertisement
moreiramota

Untitled

Dec 8th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. public List<Pair<String, Integer>> a6_Ordena1(List<String> morses, String tipo,BST<Morse>bst) {
  2. List<Pair<String, Integer>> aux = new ArrayList<>();
  3. for (String s : morses) {
  4. Pair<String, Integer> p = a6_morseDecoder(s, tipo);
  5. if (p.getValue() != 0) {
  6. aux.add(p);
  7. }
  8. }
  9. a6_OrdenaTipo(aux);
  10. return aux;
  11. }
  12.  
  13. private Pair<String, Integer> a6_morseDecoder(String morse, String tipo) {
  14. String chars[] = morse.split(" ");
  15. String palavra = "";
  16. int contador = 0;
  17. int j = 0;
  18. for (int i = 0; i < chars.length; i++) {
  19. char cod[];
  20. cod = chars[i].toCharArray();
  21. Morse c = a2_morseDecoder(bst.root, cod, j, chars[i]);
  22. if (c.getTipo().compareToIgnoreCase(tipo) == 0) {
  23. contador++;
  24. }
  25. palavra += c.getLetra();
  26. }
  27. Pair<String, Integer> p = new Pair<>("", 0);
  28. if (contador != 0) {
  29. p = new Pair<>(palavra, contador);
  30. }
  31. return p;
  32. }
  33.  
  34. private void a6_OrdenaTipo(List<Pair<String, Integer>> ordenada) {
  35. System.out.println("ola");
  36. for (int i = 0; i < ordenada.size() - 1; i++) {
  37. for (int j = i+1; j < ordenada.size(); j++) {
  38. System.out.println("");
  39. if (ordenada.get(i).getValue() < ordenada.get(j).getValue()) {
  40. Pair<String, Integer> menor = ordenada.get(i);
  41. ordenada.set(i, ordenada.get(j));
  42. ordenada.set(j, menor);
  43. }
  44. }
  45. }
  46. }
  47.  
  48. private Morse a2_morseDecoder(Node<Morse> node, char[] cod, int i, String aux) {
  49. if (aux == null) {
  50. return null;
  51. }
  52. if (aux.compareTo(node.getElement().getMorse()) == 0) {
  53. return node.getElement();
  54. }
  55. if (i < cod.length) {
  56. if (cod[i] == '.') {
  57. return a2_morseDecoder(node.getLeft(), cod, ++i, aux);
  58. } else {
  59. return a2_morseDecoder(node.getRight(), cod, ++i, aux);
  60. }
  61. }
  62. return new Morse("/", " ", "Espaço");
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement