└── src ├── tp4 ├── Main.java ├── GrafoNoDirigido.java ├── Arco.java ├── Grafo.java └── GrafoDirigido.java ├── tp1 ├── Node.java └── MySimpleLinkedList.java └── tp2 ├── TreeNode.java └── Tree.java /src/tp4/Main.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unicen/Programacion3/HEAD/src/tp4/Main.java -------------------------------------------------------------------------------- /src/tp1/Node.java: -------------------------------------------------------------------------------- 1 | package ProgramacionIII.tp1; 2 | 3 | public class Node { 4 | 5 | private T info; 6 | private Node next; 7 | 8 | public Node() { 9 | this.info = null; 10 | this.next = null; 11 | } 12 | 13 | public Node(T info, Node next) { 14 | this.setInfo(info); 15 | this.setNext(next); 16 | } 17 | 18 | public Node getNext() { 19 | return next; 20 | } 21 | 22 | public void setNext(Node next) { 23 | this.next = next; 24 | } 25 | 26 | public T getInfo() { 27 | return info; 28 | } 29 | 30 | public void setInfo(T info) { 31 | this.info = info; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/tp4/GrafoNoDirigido.java: -------------------------------------------------------------------------------- 1 | package ProgramacionIII.tp4; 2 | 3 | public class GrafoNoDirigido extends GrafoDirigido { 4 | 5 | @Override 6 | public void agregarArco(int verticeId1, int verticeId2, T etiqueta) { 7 | super.agregarArco(verticeId1, verticeId2, etiqueta); 8 | super.agregarArco(verticeId2, verticeId1, etiqueta); 9 | } 10 | 11 | @Override 12 | public void borrarArco(int verticeId1, int verticeId2) { 13 | super.borrarArco(verticeId1, verticeId2); 14 | super.borrarArco(verticeId2, verticeId1); 15 | } 16 | 17 | @Override 18 | public int cantidadArcos() { 19 | return super.cantidadArcos() / 2; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/tp2/TreeNode.java: -------------------------------------------------------------------------------- 1 | package ProgramacionIII.tp2; 2 | 3 | public class TreeNode { 4 | 5 | private Integer value; 6 | private TreeNode left; 7 | private TreeNode right; 8 | 9 | public TreeNode(Integer value) { 10 | this.value = value; 11 | this.left = null; 12 | this.right = null; 13 | } 14 | 15 | public TreeNode getLeft() { 16 | return left; 17 | } 18 | 19 | public void setLeft(TreeNode left) { 20 | this.left = left; 21 | } 22 | 23 | public TreeNode getRight() { 24 | return right; 25 | } 26 | 27 | public void setRight(TreeNode right) { 28 | this.right = right; 29 | } 30 | 31 | public Integer getValue() { 32 | return value; 33 | } 34 | 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/tp1/MySimpleLinkedList.java: -------------------------------------------------------------------------------- 1 | package ProgramacionIII.tp1; 2 | 3 | public class MySimpleLinkedList { 4 | 5 | private Node first; 6 | 7 | public MySimpleLinkedList() { 8 | this.first = null; 9 | } 10 | 11 | public void insertFront(T info) { 12 | Node tmp = new Node(info,null); 13 | tmp.setNext(this.first); 14 | this.first = tmp; 15 | } 16 | 17 | public T extractFront() { 18 | // TODO 19 | return null; 20 | } 21 | 22 | public boolean isEmpty() { 23 | // TODO 24 | return false; 25 | } 26 | 27 | public T get(int index) { 28 | // TODO 29 | return null; 30 | } 31 | 32 | public int size() { 33 | // TODO 34 | return 0; 35 | } 36 | 37 | @Override 38 | public String toString() { 39 | // TODO 40 | return ""; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/tp2/Tree.java: -------------------------------------------------------------------------------- 1 | package ProgramacionIII.tp2; 2 | 3 | public class Tree { 4 | 5 | private TreeNode root; 6 | 7 | public Tree() { 8 | this.root = null; 9 | } 10 | 11 | public void add(Integer value) { 12 | if (this.root == null) 13 | this.root = new TreeNode(value); 14 | else 15 | this.add(this.root,value); 16 | } 17 | 18 | private void add(TreeNode actual, Integer value) { 19 | if (actual.getValue() > value) { 20 | if (actual.getLeft() == null) { 21 | TreeNode temp = new TreeNode(value); 22 | actual.setLeft(temp); 23 | } else { 24 | add(actual.getLeft(),value); 25 | } 26 | } else if (actual.getValue() < value) { 27 | if (actual.getRight() == null) { 28 | TreeNode temp = new TreeNode(value); 29 | actual.setRight(temp); 30 | } else { 31 | add(actual.getRight(),value); 32 | } 33 | } 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/tp4/Arco.java: -------------------------------------------------------------------------------- 1 | package ProgramacionIII.tp4; 2 | 3 | /* 4 | * La clase arco representa un arco del grafo. Contiene un vertice origen, un vertice destino y una etiqueta. 5 | * Nota: Para poder exponer los arcos fuera del grafo y que nadie los modifique se hizo esta clase inmutable 6 | * (Inmutable: una vez creado el arco no es posible cambiarle los valores). 7 | */ 8 | public class Arco { 9 | 10 | private int verticeOrigen; 11 | private int verticeDestino; 12 | private T etiqueta; 13 | 14 | public Arco(int verticeOrigen, int verticeDestino, T etiqueta) { 15 | this.verticeOrigen = verticeOrigen; 16 | this.verticeDestino = verticeDestino; 17 | this.etiqueta = etiqueta; 18 | } 19 | 20 | public int getVerticeOrigen() { 21 | return verticeOrigen; 22 | } 23 | 24 | public int getVerticeDestino() { 25 | return verticeDestino; 26 | } 27 | 28 | public T getEtiqueta() { 29 | return etiqueta; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/tp4/Grafo.java: -------------------------------------------------------------------------------- 1 | package ProgramacionIII.tp4; 2 | 3 | import java.util.Iterator; 4 | 5 | public interface Grafo { 6 | 7 | // Agrega un vertice 8 | public void agregarVertice(int verticeId); 9 | 10 | // Borra un vertice 11 | public void borrarVertice(int verticeId); 12 | 13 | // Agrega un arco con una etiqueta, que conecta el verticeId1 con el verticeId2 14 | public void agregarArco(int verticeId1, int verticeId2, T etiqueta); 15 | 16 | // Borra el arco que conecta el verticeId1 con el verticeId2 17 | public void borrarArco(int verticeId1, int verticeId2); 18 | 19 | // Verifica si existe un vertice 20 | public boolean contieneVertice(int verticeId); 21 | 22 | // Verifica si existe un arco entre dos vertices 23 | public boolean existeArco(int verticeId1, int verticeId2); 24 | 25 | // Obtener el arco que conecta el verticeId1 con el verticeId2 26 | public Arco obtenerArco(int verticeId1, int verticeId2); 27 | 28 | // Devuelve la cantidad total de vertices en el grafo 29 | public int cantidadVertices(); 30 | 31 | // Devuelve la cantidad total de arcos en el grafo 32 | public int cantidadArcos(); 33 | 34 | // Obtiene un iterador que me permite recorrer todos los vertices almacenados en el grafo 35 | public Iterator obtenerVertices(); 36 | 37 | // Obtiene un iterador que me permite recorrer todos los vertices adyacentes a verticeId 38 | public Iterator obtenerAdyacentes(int verticeId); 39 | 40 | // Obtiene un iterador que me permite recorrer todos los arcos del grafo 41 | public Iterator> obtenerArcos(); 42 | 43 | // Obtiene un iterador que me permite recorrer todos los arcos que parten desde verticeId 44 | public Iterator> obtenerArcos(int verticeId); 45 | 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/tp4/GrafoDirigido.java: -------------------------------------------------------------------------------- 1 | package ProgramacionIII.tp4; 2 | 3 | import java.util.Iterator; 4 | 5 | public class GrafoDirigido implements Grafo { 6 | 7 | @Override 8 | public void agregarVertice(int verticeId) { 9 | // TODO Auto-generated method stub 10 | } 11 | 12 | @Override 13 | public void borrarVertice(int verticeId) { 14 | // TODO Auto-generated method stub 15 | } 16 | 17 | @Override 18 | public void agregarArco(int verticeId1, int verticeId2, T etiqueta) { 19 | // TODO Auto-generated method stub 20 | } 21 | 22 | @Override 23 | public void borrarArco(int verticeId1, int verticeId2) { 24 | // TODO Auto-generated method stub 25 | } 26 | 27 | @Override 28 | public boolean contieneVertice(int verticeId) { 29 | // TODO Auto-generated method stub 30 | return false; 31 | } 32 | 33 | @Override 34 | public boolean existeArco(int verticeId1, int verticeId2) { 35 | // TODO Auto-generated method stub 36 | return false; 37 | } 38 | 39 | @Override 40 | public Arco obtenerArco(int verticeId1, int verticeId2) { 41 | // TODO Auto-generated method stub 42 | return null; 43 | } 44 | 45 | @Override 46 | public int cantidadVertices() { 47 | // TODO Auto-generated method stub 48 | return 0; 49 | } 50 | 51 | @Override 52 | public int cantidadArcos() { 53 | // TODO Auto-generated method stub 54 | return 0; 55 | } 56 | 57 | @Override 58 | public Iterator obtenerVertices() { 59 | // TODO Auto-generated method stub 60 | return null; 61 | } 62 | 63 | @Override 64 | public Iterator obtenerAdyacentes(int verticeId) { 65 | // TODO Auto-generated method stub 66 | return null; 67 | } 68 | 69 | @Override 70 | public Iterator> obtenerArcos() { 71 | // TODO Auto-generated method stub 72 | return null; 73 | } 74 | 75 | @Override 76 | public Iterator> obtenerArcos(int verticeId) { 77 | // TODO Auto-generated method stub 78 | return null; 79 | } 80 | 81 | } 82 | --------------------------------------------------------------------------------