TrabalhosGratuitos.com - Trabalhos, Monografias, Artigos, Exames, Resumos de livros, Dissertações
Pesquisar

Estrutura de dados exercício

Por:   •  15/6/2016  •  Exam  •  723 Palavras (3 Páginas)  •  223 Visualizações

Página 1 de 3

Trabalho de Estrutura de Dados

Jailson Carvalho Santos

1) Crie um método em SimpleList.java que faça a inserção ordenada de notas dos alunos na lista.

import java.util.Scanner;

public class {

public static void main (String args[])

{ SimpleList simpleList = new SimpleList();

Scanner entrada = new Scanner (System.in)System.out.println("Tamanho da lista: " + SimpleList.getSize());

}

}

2) Crie um método que busque um aluno em uma pilha pesquisando por sua matrícula. Se aluno for encontrado, deve ser retornado se objeto; caso contrário, deve ser retornado nulo.

public class {

private ListNode top;

public Q5() {

this.top = null;

}

public void push (Object newItem) {

if (isEmpty()) {

top = new ListNode(newItem);

}

else {

top = new ListNode(newItem, top);

}

}

public void pop() throws EmptyListException {

if (isEmpty()) {

throw new EmptyListException();

}

else{

top = top.next;

}

}

public boolean isEmpty() {

return top == null;

}

public void print() {

if (isEmpty()) {

System.out.println("A pilha está vazia");

return;

}

ListNode current = top;

while (current != null) { System.out.print(current.data.toString() + " "); current = current.next;

} System.out.print("\n");

}

public Aluno pesquisarMatricula (int matricula){

if (isEmpty()) {

System.out.println("A pilha está vazia");

return null;

}

ListNode current = top;

while (current != null) {

Aluno aluno = (Aluno) current.data;

if(aluno.getMatricula() == matricula){

return aluno;

}

current = current.next;

}

return null;

}

}

3) Faça um método que permita busca um aluno e uma árvore pesquisando por sua matrícula. Se aluno for encontrado, deve ser retornado se objeto; caso contrário, deve ser retornado nulo.

public class {

public static void main(String args[]){

/*

BinaryTree binaryTree = new BinaryTree('F');

TreeNode nodeF = binaryTree.root;

TreeNode nodeB = binaryTree.intertLeft(nodeF, 'B');

TreeNode nodeA = binaryTree.intertLeft(nodeB, 'A');

TreeNode nodeD = binaryTree.intertRight(nodeB, 'D');

TreeNode nodeC = binaryTree.intertLeft(nodeD, 'C');

TreeNode nodeE = binaryTree.intertRight(nodeD, 'E'); ]

TreeNode nodeH = binaryTree.intertRight(nodeF, 'H');

TreeNode nodeG = binaryTree.intertLeft(nodeH, 'G');

 TreeNode nodeI = binaryTree.intertRight(nodeH, 'I');

binaryTree.preOrder();

System.out.println();

binaryTree.inOrder();

System.out.println();

binaryTree.postOrder();

*/

Aluno aluno = new Aluno(1, "Amanda");

Aluno aluno2 = new Aluno(2, "Lara");

 Aluno aluno3 = new Aluno(3, "Francisco");

BinaryTree binaryTree = new BinaryTree(aluno);

TreeNode nodeF = binaryTree.root;

TreeNode noA = binaryTree.intertLeft(nodeF, aluno2);

TreeNode noB = binaryTree.intertRight(nodeF, aluno3);

Aluno pesquisa = binaryTree.pesquisaMatricula(2, binaryTree.root);

if(pesquisa == null){

System.out.println("Aluno não encontrado");

}

else{

System.out.println("Aluno Encontrado:: " + pesquisa.getNome());

}

}

}

4) Faça um método que permita busca um aluno e uma árvore pesquisando por sua matrícula. Se aluno for encontrado, deve ser retornado se objeto; caso contrário, deve ser retornado nulo.

public class {

public static void main(String args[]){

/*

BinaryTree binaryTree = new BinaryTree('F');

TreeNode nodeF = binaryTree.root;

TreeNode nodeB = binaryTree.intertLeft(nodeF, 'B');

TreeNode nodeA = binaryTree.intertLeft(nodeB, 'A');

TreeNode nodeD = binaryTree.intertRight(nodeB, 'D');

TreeNode nodeC = binaryTree.intertLeft(nodeD, 'C');

TreeNode nodeE = binaryTree.intertRight(nodeD, 'E'); ]

TreeNode nodeH = binaryTree.intertRight(nodeF, 'H');

TreeNode nodeG = binaryTree.intertLeft(nodeH, 'G');

 TreeNode nodeI = binaryTree.intertRight(nodeH, 'I');

binaryTree.preOrder();

System.out.println();

binaryTree.inOrder();

System.out.println();

binaryTree.postOrder();

*/

Aluno aluno = new Aluno(1, "Amanda");

...

Baixar como (para membros premium)  txt (6.3 Kb)   pdf (84.9 Kb)   docx (13.3 Kb)  
Continuar por mais 2 páginas »
Disponível apenas no TrabalhosGratuitos.com