Advertisement
cesarnascimento

fila node

Mar 9th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.62 KB | None | 0 0
  1. package filas;
  2.  
  3. public class listaNode {
  4.  
  5.      Node front = null;
  6.      Node back = null;
  7.      
  8.      public void enqueue(Node i) {
  9.          if(front == null && back == null) {
  10.              front = back = i;
  11.          }else {
  12.              back.setNext(i);
  13.              i.setPrevious(back);
  14.              back = i;   
  15.          }
  16.      }
  17.      
  18.      public void dequeue() {
  19.          if(front == null && back == null) {   
  20.              System.out.println("Lista vazia!!!!");
  21.          }else {
  22.              front = front.getNext();
  23.              front.setPrevious(null);
  24.          }
  25.      }
  26. }
  27.  
  28. //fila
  29.  
  30. package filas;
  31.  
  32. public class lista {
  33.     int front = 0;
  34.     int back = 0;
  35.     int[] queue;
  36.     int aux = 0;
  37.  
  38.     public lista() {
  39.         queue = new int[4];
  40.  
  41.     }
  42.  
  43.     public void enqueue(int info) {
  44.         if (back == 0) {
  45.             queue[back] = info;
  46.             back++;
  47.  
  48.             if (back == queue.length) {
  49.                 back = 0;
  50.             }
  51.         } else if (back == front) {
  52.             System.out.println("Lista cheia!!!!!!");
  53.         } else {
  54.             queue[back] = info;
  55.             back++;
  56.         }
  57.     }
  58.  
  59.     public int dequeue() {
  60.  
  61.         if (front == queue.length) {
  62.             front = 0;
  63.         } else if (front > back) {
  64.             System.out.println("Lisa cheia!!!");
  65.  
  66.         } else {
  67.             queue[front] = aux;
  68.             queue[front] = 0;
  69.             front++;
  70.         }
  71.  
  72.         return aux;
  73.  
  74.     }
  75. }
  76.  
  77. //
  78. package filas;
  79.  
  80. public class Node {
  81.  
  82.     private int info;
  83.     private Node next = null;
  84.     private Node previous = null;
  85.  
  86.     public Node getNext() {
  87.         return next;
  88.     }
  89.  
  90.     public void setNext(Node next) {
  91.         this.next = next;
  92.     }
  93.  
  94.     public Node getPrevious() {
  95.         return previous;
  96.     }
  97.  
  98.     public void setPrevious(Node previous) {
  99.         this.previous = previous;
  100.     }
  101.  
  102.     public int getInfo() {
  103.         return info;
  104.     }
  105.  
  106.     public void setInfo(int info) {
  107.         this.info = info;
  108.     }
  109.  
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement