Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package tgraph;
- import java.util.ArrayList;
- import java.util.LinkedList;
- import java.util.List;
- /**
- *
- * @author Hubert
- */
- public class LGraph extends AGraph{
- ArrayList<ArrayList<Integer> > lista;
- //
- public static void main(String[] args) {
- LGraph L=new LGraph(5);
- L.connect(1, 2);
- L.connect(4, 3);
- L.writeMatrix();
- }
- public LGraph(int vertexCount) {
- super(vertexCount);
- lista = new ArrayList<ArrayList<Integer> >(size);
- for (int i = 0; i < size; i++)
- lista.add(new ArrayList<Integer>());
- }
- @Override
- public void writeMatrix() {
- for(int i=0;i<lista.size();i++){
- for(int j=0;j<lista.get(i).size();j++)
- {
- System.out.print(lista.get(i).get(j)+" ");
- if(j==lista.get(i).size()-1)
- System.out.println();
- }
- }
- }
- @Override
- public boolean check(int i, int j) throws IllegalArgumentException {
- if(lista.get(i).contains(j))
- return true;
- else
- return false;
- }
- @Override
- public void connect(int i, int j) throws IllegalArgumentException {
- lista.get(i).add(j);
- lista.get(j).add(i);
- }
- @Override
- public void writeList() {
- for(int i=0;i<lista.size();i++){
- System.out.println("Wartosci dla "+i);
- for(int j=0;j<lista.get(i).size();j++)
- {
- System.out.println(lista.get(i).get(j)+" ");
- }
- }
- }
- }
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package tgraph;
- /**
- *
- * @author Hubert
- */
- public class TGraph extends AGraph {
- int [] [] tab=new int [size][size];
- public static void main(String[] args) {
- TGraph t= new TGraph(5);
- t.connect(1, 4);
- t.connect(1, 3);
- t.writeMatrix();
- t.writeList();
- }
- public TGraph(int vertexCount) {
- super(vertexCount);
- }
- @Override
- public void writeMatrix() {
- for(int i=0;i<size;i++)
- for(int j=0;j<size;j++)
- {
- System.out.print(tab[i][j]);
- if(j==size-1)
- System.out.println();
- }
- }
- @Override
- public boolean check(int i, int j) throws IllegalArgumentException {
- if(tab[i][j]==1)
- return true;
- else
- return false;
- }
- @Override
- public void connect(int i, int j) throws IllegalArgumentException {
- tab[i][j]=1;
- }
- @Override
- public void writeList() {
- int pomoc_i=0, pomoc_j=0;
- for(int i=0;i<size;i++){
- pomoc_i=i;
- System.out.println(pomoc_i+": ");
- for(int j=0;j<size;j++)
- {
- pomoc_j=j;
- if(tab[i][j]!=0)
- System.out.print(" "+j);
- }
- System.out.println();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement