Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static Scanner scanner = new Scanner(System.in);
- static ArrayList<Node> pontok = new ArrayList<>();
- static int[][] elek;
- static int ciklusDb = 0;
- static int elagazasDb = 0;
- static class Node{
- int parent;
- int ertek;
- public ArrayList<Integer> szomszedok = new ArrayList<>();
- Node(int a){
- this.ertek = a;
- }
- }
- public static void main(String[] args)
- {
- int pontDb = 10;
- int elDb = 12;
- elek = new int[][]{
- {1, 2},
- {2, 3},
- {3, 4},
- {4, 6},
- {6, 7},
- {6, 8},
- {7, 4},
- {3, 5},
- {5, 9},
- {9, 10},
- {10, 5},
- {10, 8}
- };
- pontok.add(new Node(1));
- for(int i = 2; i <= pontDb; i++) {
- pontok.add(new Node(i));
- GetNeighbours(pontok.get(i-1));
- for(int j = 0; j < pontok.get(i-1).szomszedok.size(); j++) {
- }
- pontok.get(i-1).szomszedok.clear();
- }
- System.out.println(ciklusDb);
- System.out.println(elagazasDb);
- }
- private static void GetNeighbours(Node i) {
- i.parent = GetParent(i);
- for(int[] a : elek) {
- if(a[0] == i.ertek && a[1] != i.parent) {
- i.szomszedok.add(a[1]);
- }
- else if(a[1] == i.ertek && a[0] != i.parent) {
- i.szomszedok.add(a[0]);
- }
- }
- System.out.println(i.ertek + "'s parent is: " + i.parent);
- System.out.print(i.ertek + "'s children are: ");
- for(int a : i.szomszedok) {
- System.out.print(a + " ");
- }
- System.out.println();
- }
- private static int GetParent(Node i) {
- for(int[] a : elek) {
- if(a[0] == i.ertek) {
- return a[1];
- }
- else if(a[1] == i.ertek) {
- return a[0];
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement