Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Customer {
- String name;
- int ticket;
- Customer(String name, int ticket) {
- this.name = name;
- this.ticket = ticket;
- }
- String getName() {
- return name;
- }
- int getTicket() {
- return ticket;
- }
- }
- public class Main {
- public static void main(String[] args) {
- Queue<Customer> queue = new LinkedList<>();
- queue.add(new Customer("a1", 1));
- queue.add(new Customer("a2", 2));
- queue.add(new Customer("a3", -1));
- queue.add(new Customer("a4", -1));
- queueAnalysis(queue);
- }
- public static void queueAnalysis(Queue<Customer> queue) {
- System.out.println("Original: " + queue + "n");
- String names[] = null;
- int cant = 0;
- int tam = queue.size();
- for (int i = 0; i < tam; i++) {
- if (queue.peek().getTicket() == -1) {
- names[i] = queue.peek().getName();
- cant++;
- queue.poll();
- }
- }
- System.out.println("colados: " + names + "n");
- System.out.println("Cola final: " +queue);
- //Customer c;
- for (Iterator it = queue.iterator(); it.hasNext();) {
- System.out.println((Customer) it.next());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement