Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public boolean cumple ()
- {Queue<Character> caux1= new colaArregloCircular<Character>();
- Stack<Character> p= new ArrayStack<Character>();
- PositionList <Character> aux=new NodePositionList<Character>();
- boolean exp=true;
- try{
- Position<Character> pos= log.first();
- while(pos!=log.last())
- {aux.addLast(pos.element());
- pos=log.next(pos);}
- aux.addLast(pos.element());
- Position<Character> actual= aux.first();
- char ch=actual.element();
- int i=1;
- while(i<aux.size() && exp)
- {while(i<aux.size() && (ch != 'x'))
- {caux1.enqueue(ch);
- p.push(ch);
- actual=aux.next(actual);
- ch=actual.element();
- i++;
- }
- if(i>aux.size())
- exp=false;
- else
- {if (controlarCola(caux1))
- {while (!p.isEmpty() && exp)
- {actual=aux.next(actual);
- ch=actual.element();
- char ch2=p.pop();
- i++;
- if(ch==ch2)
- {}
- else exp=false;}
- }
- else exp=false;
- }
- if( i<aux.size())
- {actual=aux.next(actual);
- ch=actual.element();
- i++;
- if(ch=='x' && i<aux.size())
- {actual=aux.next(actual);
- ch=actual.element();
- i++;}
- else exp=false;
- }
- }
- return exp;}
- catch (TDAPila.EmptyStackException e)
- {System.out.println(e.getMessage());}
- catch (InvalidPositionException e)
- {System.out.println(e.getMessage());}
- catch (EmptyListException e)
- {System.out.println(e.getMessage());}
- catch (BoundaryViolationException e)
- {System.out.println(e.getMessage());}
- return exp;
- }
- /**
- * Es un metodo privado que consulta si la cola pasada por parametro
- * cumple con el formato CzCC
- *
- * @param c Cola de caracteres.
- *
- * @return Verdadero si cumple, en caso contrario retorna falso.
- */
- private static boolean controlarCola(Queue<Character> c)
- {Queue<Character> caux= new colaArregloCircular<Character>();
- int cant=0;
- int i=0;
- boolean control=true;
- try{
- char ch=c.dequeue();
- if (ch=='z' && cant==c.size())
- control=true;
- else
- {while(ch!='z' && !c.isEmpty())
- {caux.enqueue(ch);
- ch=c.dequeue();
- cant++;}
- if(c.isEmpty())
- control=false;
- else
- {while( i<= 2*cant && !c.isEmpty() && control)
- {ch=c.dequeue();
- char chaux= caux.dequeue();
- if(ch==chaux)
- {i=i+1;
- caux.enqueue(chaux);}
- else control=false;
- }
- if (i!=cant*2)
- control=false;
- }
- }
- return control;}
- catch (EmptyQueueException e)
- {System.out.println(e.getMessage());}
- return control;}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement