Advertisement
Guest User

codigo

a guest
Dec 15th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. package ads.estrutura.busca;
  2.  
  3. import java.lang.String;
  4. import java.util.Collections;
  5. import java.util.ArrayList;
  6.  
  7.  
  8. public class Turma {
  9.  
  10.  
  11. ArrayList<String> alunos = new ArrayList<String> ();
  12.  
  13. public void matriculaAluno(String novoaluno) {
  14. // TODO Auto-generated method stub
  15. alunos.add(novoaluno);
  16. }
  17.  
  18. public boolean buscaBinariaDeAluno(String NomedoAluno) {
  19. // TODO Auto-generated method stub
  20. int inicio = 0;
  21. int fim = alunos.size() -1;
  22.  
  23. while(inicio <= fim) {
  24. int meio = (inicio + fim) / 2;
  25.  
  26. if(alunos.get(meio).equals(NomedoAluno)){
  27. return true;
  28. }else if(alunos.get(meio).compareTo(NomedoAluno) < 0){
  29. inicio = meio + 1;
  30. }else {
  31. fim = meio - 1;
  32. }
  33.  
  34. }
  35. return false;
  36. }
  37.  
  38.  
  39. public boolean buscaSequencialDeAluno(String NomeDoAluno) {
  40. // TODO Auto-generated method stub
  41. for(String aluno : alunos) {
  42. if(aluno.equals(NomeDoAluno)) {
  43. return true;
  44. }
  45. }
  46. return false;
  47. }
  48.  
  49.  
  50. public boolean buscaComContains(String Nomedoaluno) {
  51. // TODO Auto-generated method stub
  52. return alunos.contains(Nomedoaluno);
  53. }
  54.  
  55.  
  56. public boolean buscaComBinarySearch(String Nomedoaluno) {
  57. // TODO Auto-generated method stub
  58. return Collections.binarySearch(alunos, Nomedoaluno) > -1;
  59. }
  60.  
  61.  
  62. public int tamanhoDaTurma() {
  63. // TODO Auto-generated method stub
  64. return alunos.size();
  65. }
  66.  
  67.  
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement