From 2bcfb0a35c1db547edef362ffc15f0cea09523b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E6=B5=B7=E5=B9=B3?= <724465012@qq.com> Date: Fri, 8 Jan 2021 19:47:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=BE=E7=9A=84=E5=9F=BA=E7=A1=80=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Matrix.java | 43 +++++++++++++++++++++++++++++++++++++++++++ Table.java | 5 +++++ Text.java | 5 +++++ 3 files changed, 53 insertions(+) create mode 100644 Matrix.java create mode 100644 Table.java create mode 100644 Text.java diff --git a/Matrix.java b/Matrix.java new file mode 100644 index 0000000..96955f7 --- /dev/null +++ b/Matrix.java @@ -0,0 +1,43 @@ +package graph; + +public class Matrix { + public char[] vertex = new char[20]; + public int lable; + int flag[] = new int[20]; + public int[][] along = new int[20][20]; + public Matrix() { + this.lable = 0; + } + public void addVertex(char place) { + vertex[lable++] = place; + } + public void addEdge(int start, int end) { + along[start][end] = 1; + along[end][start] = 1; + } + public void printMatrix() { + System.out.print(" "); + for(int p = 0; p < lable; p++) System.out.print(vertex[p]+" "); + System.out.println(); + for(int i = 0; i < lable; i++) { + System.out.print(vertex[i]+" "); + for(int j = 0; j < lable; j++) System.out.print(along[i][j]+" "); + System.out.println(); + } + } + public void depth() { + flag[0] = 1; + System.out.print(vertex[0]); + dfs(0); + System.out.println(); + } + public void dfs(int n) { + for (int s = n; s < lable; s++) + for (int v = n; v < lable; v++) + if(along[s][v] == 1 && flag[v] != 1) { + flag[v] = 1; + System.out.print(vertex[v]); + dfs(v); + } + } +} diff --git a/Table.java b/Table.java new file mode 100644 index 0000000..d82812a --- /dev/null +++ b/Table.java @@ -0,0 +1,5 @@ +package graph; + +public class Table { + +} diff --git a/Text.java b/Text.java new file mode 100644 index 0000000..b0bc7d6 --- /dev/null +++ b/Text.java @@ -0,0 +1,5 @@ +package graph; + +public class Text { + +} -- Gitee