A apresentação está carregando. Por favor, espere

A apresentação está carregando. Por favor, espere

Programação II Prof. Mateus Raeder Universidade do Vale do Rio dos Sinos - São Leopoldo -

Apresentações semelhantes


Apresentação em tema: "Programação II Prof. Mateus Raeder Universidade do Vale do Rio dos Sinos - São Leopoldo -"— Transcrição da apresentação:

1 Programação II Prof. Mateus Raeder Universidade do Vale do Rio dos Sinos - São Leopoldo -

2 Programação II – Prof. Mateus Raeder Questão 1 public boolean remove(String obj){ if (isEmpty()) { System.out.println("Empty " + name); return false; } Node current = firstNode; Node aux = null; if(current.getData() == obj){ firstNode = current.getNext(); return true; }

3 Programação II – Prof. Mateus Raeder Questão 1 while(current.getNext() != null){ if(current.getNext().getData() == obj){ //remove aux = current.getNext(); current.setNext(aux.getNext()); return true; } aux = current; current = current.getNext(); }

4 Programação II – Prof. Mateus Raeder Questão 1 if(current.getData() == obj){ lastNode = aux; lastNode.setNext(null); return true; } return false; }

5 Programação II – Prof. Mateus Raeder Questão 2 /* Questão 2 * método insertAfter */ public boolean insertAfter(String obj1, String obj2){ Node current = firstNode; while(current != null){ if(current.getData() == obj1){ current.setNext(new Node(obj2, current.getNext())); return true; } current = current.getNext(); } return false; }

6 Programação II – Prof. Mateus Raeder Questão 4 public class Questao4{ public static void main(String args[]){ List l = new List(); Teclado t = new Teclado(); int num; for(int i=0; i<10; i++){ num = t.leInt("Digite um numero: "); if(num < 0) l.insertAtBack(num); } l.print(); }

7 Programação II – Prof. Mateus Raeder Questão 5 /* Questão 5 * método find */ public int find(String o){ Node current = firstNode; int posicao = 0; while(current != null){ if(current.getData() == o){ return posicao; } posicao++; current = current.getNext(); } return -1; }

8 Programação II – Prof. Mateus Raeder Questão 6 public class Questao6{ public List concatena(List x, List y){ List z = new List(); try{ while(!x.isEmpty()) z.insertAtBack(x.removeFromFront()); while(!y.isEmpty()) z.insertAtBack(y.removeFromFront()); }catch(UnderflowException e){ System.out.println(e.toString()); } return z; }

9 Programação II – Prof. Mateus Raeder Questão 6 public static void main(String args[]){ Questao6 a = new Questao6(); List x = new List(); List y = new List(); x.insertAtBack("A"); x.insertAtBack("B"); x.insertAtBack("C"); x.insertAtBack("D"); x.print(); y.insertAtBack("E"); y.insertAtBack("F"); y.insertAtBack("G"); y.insertAtBack("H"); List z = a.concatena(x, y); x.print(); y.print(); z.print(); }

10 Programação II – Prof. Mateus Raeder Questão 7 public class Questao7{ public static void main(String args[]){ Teclado t = new Teclado(); Queue f = new Queue(); Stack p = new Stack();

11 Programação II – Prof. Mateus Raeder Questão 7 int num = t.leInt("Digite o número:"); while(num != 999){ if(num > 0) f.enqueue(num+""); if(num < 0) p.push(num+""); if(num == 0){ try{ System.out.println("Retirei da pilha: "+p.pop()); System.out.println("Retirei da fila: "+f.dequeue()); }catch(UnderflowException e){ System.out.println(e.toString()); } System.out.println("Situação da pilha:"); p.print(); System.out.println("Situação da fila:"); f.print(); num = t.leInt("Digite o número:"); }

12 Programação II – Prof. Mateus Raeder Questão 8 /* * Questão 8 */ public Queue inverte(){ Queue q = new Queue(); Stack s = new Stack(); try{ while(!isEmpty()) s.push(dequeue()); while(!s.isEmpty()) q.enqueue(s.pop()); }catch(UnderflowException e){ System.out.println(e.toString()); } return q; }

13 Programação II – Prof. Mateus Raeder Questão 9 public class Questao9{ public static void main(String args[]){ Stack p1 = new Stack(); Stack p2 = new Stack(); Stack p3 = new Stack(); p1.push("A"); p1.push("B"); p1.push("C"); p1.push("D"); p1.push("E"); p1.push("F"); try{ while(!p1.isEmpty()) p3.push(p1.pop()); while(!p3.isEmpty()) p2.push(p3.pop()); }catch(UnderflowException e){ System.out.println(e.toString()); } p2.print(); }


Carregar ppt "Programação II Prof. Mateus Raeder Universidade do Vale do Rio dos Sinos - São Leopoldo -"

Apresentações semelhantes


Anúncios Google