Advertisement
Guest User

Untitled

a guest
Apr 17th, 2014
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1. public boolean cumple ()
  2. {Queue<Character> caux1= new colaArregloCircular<Character>();
  3. Stack<Character> p= new ArrayStack<Character>();
  4. PositionList <Character> aux=new NodePositionList<Character>();
  5. boolean exp=true;
  6. try{
  7. Position<Character> pos= log.first();
  8. while(pos!=log.last())
  9. {aux.addLast(pos.element());
  10. pos=log.next(pos);}
  11. aux.addLast(pos.element());
  12. Position<Character> actual= aux.first();
  13.  
  14. char ch=actual.element();
  15.  
  16. int i=1;
  17. while(i<aux.size() && exp)
  18. {while(i<aux.size() && (ch != 'x'))
  19. {caux1.enqueue(ch);
  20. p.push(ch);
  21. actual=aux.next(actual);
  22. ch=actual.element();
  23. i++;
  24. }
  25.  
  26. if(i>aux.size())
  27. exp=false;
  28. else
  29. {if (controlarCola(caux1))
  30. {while (!p.isEmpty() && exp)
  31. {actual=aux.next(actual);
  32. ch=actual.element();
  33. char ch2=p.pop();
  34. i++;
  35. if(ch==ch2)
  36. {}
  37. else exp=false;}
  38. }
  39.  
  40. else exp=false;
  41. }
  42.  
  43. if( i<aux.size())
  44. {actual=aux.next(actual);
  45. ch=actual.element();
  46. i++;
  47. if(ch=='x' && i<aux.size())
  48. {actual=aux.next(actual);
  49. ch=actual.element();
  50. i++;}
  51. else exp=false;
  52. }
  53. }
  54. return exp;}
  55.  
  56. catch (TDAPila.EmptyStackException e)
  57. {System.out.println(e.getMessage());}
  58. catch (InvalidPositionException e)
  59. {System.out.println(e.getMessage());}
  60. catch (EmptyListException e)
  61. {System.out.println(e.getMessage());}
  62. catch (BoundaryViolationException e)
  63. {System.out.println(e.getMessage());}
  64. return exp;
  65. }
  66.  
  67.  
  68. /**
  69. * Es un metodo privado que consulta si la cola pasada por parametro
  70. * cumple con el formato CzCC
  71. *
  72. * @param c Cola de caracteres.
  73. *
  74. * @return Verdadero si cumple, en caso contrario retorna falso.
  75. */
  76. private static boolean controlarCola(Queue<Character> c)
  77. {Queue<Character> caux= new colaArregloCircular<Character>();
  78. int cant=0;
  79. int i=0;
  80. boolean control=true;
  81. try{
  82. char ch=c.dequeue();
  83. if (ch=='z' && cant==c.size())
  84. control=true;
  85. else
  86. {while(ch!='z' && !c.isEmpty())
  87. {caux.enqueue(ch);
  88. ch=c.dequeue();
  89. cant++;}
  90. if(c.isEmpty())
  91. control=false;
  92. else
  93. {while( i<= 2*cant && !c.isEmpty() && control)
  94. {ch=c.dequeue();
  95. char chaux= caux.dequeue();
  96. if(ch==chaux)
  97. {i=i+1;
  98. caux.enqueue(chaux);}
  99. else control=false;
  100. }
  101.  
  102. if (i!=cant*2)
  103. control=false;
  104. }
  105. }
  106. return control;}
  107.  
  108. catch (EmptyQueueException e)
  109. {System.out.println(e.getMessage());}
  110.  
  111. return control;}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement