Baixe o app para aproveitar ainda mais
Prévia do material em texto
4/19/22, 8:52 AM Online Java Compiler - Online Java Editor - Java Code Online https://www.jdoodle.com/online-java-compiler/ 1/4 Online Java Compiler IDE For Multiple Files, Custom Library and File Read/Write, use our new - Advanced Java IDE import java.util.ArrayList; import java.util.LinkedList; import java.util.Queue; import java.util.Stack; public class A3{ public static void main(String [] args) {ArrayList <Integer> lista = new ArrayList <> (5) Stack<Integer> pilha = new Stack <> (); Queue<Integer> fila = new LinkedList <> (); lista.add (1); lista.add (2); lista.add (3); lista.add (4); lista.add (5); System.out.printf("Lista: %s\nPilha: %s\nFila: %s\n\n", lista, pilha, fila); while (!lista.isEmpty()){ int elemento = lista.remove(0); pilha.push(elemento); System.out.printf("Lista: %s\nPilha: %s\nFila: %s\n\n", lista, pilha, fila); } while(!lista.isEmpty()) {int elemento = pilha.pop(); fila.add (elemento); System.out.printf("Lista: %s\nPilha: %s\nFila: %s\n\n", lista, pilha, fila); } lista.add (6); lista.add (7); lista.add (8); lista.add (9); lista.add (10); System.out.println("Inserindo v alor es [6, 7, 8, 9 e 10] na lista:"); System.out.printf("Lista: %s\nPilha: %s\nFila: %s\n\n", lista, pilha, fila); while(!lista.isEmpty()){ int elemento = lista.remove(0); pilha.push(elemento); System.out.printf("Lista: %s\nPilha: %s\nFila: %s\n\n", lista, pilha, fila); } while(!pilha.isEmpty()) { int elemento pilha pop(); 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 This website uses cookies to ensure you get the best experience on our website. Got it! https://www.jdoodle.com/ https://www.jdoodle.com/online-java-compiler-ide/ 4/19/22, 8:52 AM Online Java Compiler - Online Java Editor - Java Code Online https://www.jdoodle.com/online-java-compiler/ 2/4 CommandLine Arguments Stdin Inputs Result CPU Time: 0.11 sec(s), Memory: 34056 kilobyte(s) compiled and executed in 0.663 sec(s) int elemento = pilha.pop(); fila.add(elemento); System.out.printf("Lista: %s\nPilha: %s\nFila: %s\n\n", lista, pilha, fila); }System.out.println("Fila final: " + fila); }} Execute Mode, Version, Inputs & Arguments Lista: [1, 2, 3, 4, 5] Pilha: [] Fila: [] Lista: [2, 3, 4, 5] Pilha: [1] Fila: [] Lista: [3, 4, 5] Pilha: [1, 2] Fila: [] Lista: [4, 5] Pilha: [1, 2, 3] Fila: [] Lista: [5] Pilha: [1, 2, 3, 4] Fila: [] Lista: [] Pilha: [1, 2, 3, 4, 5] Fila: [] Inserindo v alor es [6, 7, 8, 9 e 10] na lista: Lista: [6, 7, 8, 9, 10] Pilha: [1, 2, 3, 4, 5] Fila: [] Lista: [7, 8, 9, 10] Pilha: [1, 2, 3, 4, 5, 6] Fila: [] Lista: [8, 9, 10] Pilha: [1, 2, 3, 4, 5, 6, 7] Fila: [] Lista: [9, 10] Pilha: [1, 2, 3, 4, 5, 6, 7, 8] Fila: [] Lista: [10] Pilha: [1, 2, 3, 4, 5, 6, 7, 8, 9] Fila: [] Lista: [] 65 66 67 68 69 70 71 72 73 This website uses cookies to ensure you get the best experience on our website. Got it! 4/19/22, 8:52 AM Online Java Compiler - Online Java Editor - Java Code Online https://www.jdoodle.com/online-java-compiler/ 3/4 Note: 1. For file operations - upload files using upload button , Files will be upload to /uploads folder. You can read those files in program from /uploads folder. To write a file from your program, write files to '/myfiles' folder. Please note the uploaded files stored in the server only for the current session. 2. For detailed documentation check - Our Documentation, or check our Youtube channel. Thanks for using our Online Java Compiler IDE to execute your program [] Pilha: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] Fila: [] Lista: [] Pilha: [1, 2, 3, 4, 5, 6, 7, 8, 9] Fila: [10] Lista: [] Pilha: [1, 2, 3, 4, 5, 6, 7, 8] Fila: [10, 9] Lista: [] Pilha: [1, 2, 3, 4, 5, 6, 7] Fila: [10, 9, 8] Lista: [] Pilha: [1, 2, 3, 4, 5, 6] Fila: [10, 9, 8, 7] Lista: [] Pilha: [1, 2, 3, 4, 5] Fila: [10, 9, 8, 7, 6] Lista: [] Pilha: [1, 2, 3, 4] Fila: [10, 9, 8, 7, 6, 5] Lista: [] Pilha: [1, 2, 3] Fila: [10, 9, 8, 7, 6, 5, 4] Lista: [] Pilha: [1, 2] Fila: [10, 9, 8, 7, 6, 5, 4, 3] Lista: [] Pilha: [1] Fila: [10, 9, 8, 7, 6, 5, 4, 3, 2] Lista: [] Pilha: [] Fila: [10, 9, 8, 7, 6, 5, 4, 3, 2, 1] Fila final: [10, 9, 8, 7, 6, 5, 4, 3, 2, 1] This website uses cookies to ensure you get the best experience on our website. Got it! https://docs.jdoodle.com/ https://www.youtube.com/channel/UCMg38oKj3kRmzksoRDEAs9Q https://play.google.com/store/apps/details?id=com.nutpan.jdoodle_app&pcampaignid=pcampaignidMKT-Other-global-all-co-prtnr-py-PartBadge-Mar2515-1 https://apps.apple.com/us/app/jdoodle/id1544598494
Compartilhar