Advertisement
Montoya-Romina-Anahi

Tp3_P1_ColaCircular

Jun 5th, 2020
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. public class ColaCircular {
  2. Nodo head;
  3. Nodo tail;
  4. public ColaCircular(){ head=tail=null;}
  5.  
  6. public boolean colaCircularVacia(){
  7. if (head == tail && head == null)
  8. return true;
  9. else
  10. return false;
  11. }
  12.  
  13. public void imprimirColaCircular(){
  14. if (colaCircularVacia())
  15. System.out.println ("La cola no contine elementos");
  16. else {
  17. Nodo auxiliar =head;
  18. while (auxiliar != tail){
  19. System.out.println("elemento: "+ auxiliar.valor);
  20. auxiliar = auxiliar.siguiente;
  21. }
  22. System.out.println("elemento: "+ tail.valor);
  23. }
  24. }
  25. public void enQueue (float numero){
  26. Nodo auxiliar = new Nodo(numero);
  27. if (colaCircularVacia()){
  28. head= auxiliar;
  29. tail = auxiliar;
  30. auxiliar.siguiente = head;
  31.  
  32. }
  33. else {
  34. tail.siguiente= auxiliar;
  35. auxiliar.siguiente = head;
  36. tail = auxiliar;
  37. }
  38.  
  39. }
  40. public float deQueue (){
  41. float elemenRecuperado=0;
  42. if (!colaCircularVacia()){
  43. if (head== tail){
  44. elemenRecuperado = head.valor;
  45. head = tail = null;
  46. }
  47. else{
  48. elemenRecuperado= head.valor;
  49. tail.siguiente=head.siguiente;
  50. head=head.siguiente;
  51. }
  52. }
  53. return elemenRecuperado;
  54.  
  55. }
  56.  
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement