From 3f9856709d092e8bb2eb125b49a87dfe4cc30a78 Mon Sep 17 00:00:00 2001 From: stefanzan Date: Wed, 30 Dec 2020 10:52:18 +0800 Subject: [PATCH 1/7] update README.md. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c7dc5aa..7c746b8 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ ### 截止日期 -2021.1.6 +2021.1.13 ### 基础 -- Gitee From 85addc50767cd9dec7d8ee83b875ad6c721dc0b3 Mon Sep 17 00:00:00 2001 From: ssp <245492694@qq.com> Date: Thu, 7 Jan 2021 18:27:44 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cc.txt | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 cc.txt diff --git a/cc.txt b/cc.txt new file mode 100644 index 0000000..527daf3 --- /dev/null +++ b/cc.txt @@ -0,0 +1,97 @@ +package MatrixTable; + + +public class CreateGraph1 { + int vlen; + int elen; + VertexNode[] vertexNodeList; + EdgeNode edgeNode; + + + public CreateGraph1(char[] vexs, char[][] edges) { + vlen = vexs.length; + elen = edges.length; + + vertexNodeList = new VertexNode[vlen]; + for (int i = 0; i < vlen; i++) { + vertexNodeList[i] = new VertexNode(); + vertexNodeList[i].vertex = vexs[i]; + vertexNodeList[i].firstedge = null; + } + + for (int i = 0; i < elen; i++) { + EdgeNode edgeNode = new EdgeNode(); + int vi = getPosition(edges[i][0], vexs); + int vj = getPosition(edges[i][1], vexs); + + edgeNode.adjvex = edges[i][1]; + edgeNode.next = vertexNodeList[vi].firstedge; + vertexNodeList[vi].firstedge = edgeNode; + } + } + + + private class VertexNode { + char vertex; + EdgeNode firstedge; + } + + + private class EdgeNode { + char adjvex; + EdgeNode next; + } + + + private int getPosition(char ch, char[] vexs) { + for (int i = 0; i < vlen; i++) + if (vexs[i] == ch) + return i; + return -1; + } + + + public void print() { + System.out.printf("AdjList:\n"); + for (int i = 0; i < vlen; i++) { + System.out.print(vertexNodeList[i].vertex + "-->"); + if (vertexNodeList[i].firstedge != null) { + EdgeNode mEdgeNode = new EdgeNode(); + mEdgeNode = vertexNodeList[i].firstedge; + System.out.print(mEdgeNode.adjvex); + while (mEdgeNode.next != null) { + mEdgeNode = mEdgeNode.next; + System.out.print(mEdgeNode.adjvex); + } + System.out.print("\n"); + } else { + System.out.print("\n"); + } + } + } + + + public static void main(String args[]) { + + char[] vexs = { + 'A', 'B', 'C', 'D' + }; + + char[][] edges = new char[][] { + { + 'A', 'B' + }, { + 'A', 'C' + }, { + 'A', 'D' + }, { + 'B', 'D' + }, { + 'C', 'D' + } + }; + + CreateGraph1 listDG = new CreateGraph1(vexs, edges); + listDG.print(); + } +} \ No newline at end of file -- Gitee From d0bb9c53b0aec68fe7a9f1ba45a3ae6fde154e30 Mon Sep 17 00:00:00 2001 From: ssp <245492694@qq.com> Date: Thu, 7 Jan 2021 18:28:19 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nn.txt | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 nn.txt diff --git a/nn.txt b/nn.txt new file mode 100644 index 0000000..e6be51b --- /dev/null +++ b/nn.txt @@ -0,0 +1,29 @@ +package MatrixExpression; +public class Weight { + + int row; + int col; + int weight; + + Weight(int row,int col,int weight) + { + this.row = row; + this.col = col; + this.weight = weight; + } + + public static void createAdjGraphic(MyAdjGraphic g, Object[] vertices, int n,Weight[] weight,int e) + throws Exception + { + + for(int i=0;i Date: Thu, 7 Jan 2021 18:28:52 +0800 Subject: [PATCH 4/7] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mm.txt | 110 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 mm.txt diff --git a/mm.txt b/mm.txt new file mode 100644 index 0000000..42f4435 --- /dev/null +++ b/mm.txt @@ -0,0 +1,110 @@ +package MatrixExpression; + +import java.util.ArrayList; + +public class MyAdjGraphic { + + static final int maxWeight=-1; + ArrayList vertices = new ArrayList(); + int[][] edges; + int numOfEdges; + + public MyAdjGraphic(int n) + { + edges = new int[n][n]; + for(int i=0;i= vertices.size())||(v2 < 0||v2 >= vertices.size())) + { + throw new Exception("v1或者v2参数越界错误!"); + } + return this.edges[v1][v2]; + + } + + + public void insertVertice(Object obj) + { + this.vertices.add(obj); + } + + + public void insertEdges(int v1,int v2,int weight) throws Exception + { + if((v1 < 0 || v1 >= vertices.size())||(v2 < 0||v2 >= vertices.size())) + { + throw new Exception("v1或者v2参数越界错误!"); + } + + this.edges[v1][v2]=weight; + this.numOfEdges++; + } + + + public void deleteEdges(int v1,int v2) throws Exception + { + if((v1 < 0 || v1 >= vertices.size())||(v2 < 0||v2 >= vertices.size())) + { + throw new Exception("v1或者v2参数越界错误!"); + } + if( v1==v2 || this.edges[v1][v2]==maxWeight)//自己到自己的边或者边不存在则不用删除。 + { + throw new Exception("边不存在!"); + } + + this.edges[v1][v2]=maxWeight; + this.numOfEdges--; + } + + + public void print() + { + for(int i=0;i Date: Thu, 7 Jan 2021 18:29:22 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bb.txt | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 bb.txt diff --git a/bb.txt b/bb.txt new file mode 100644 index 0000000..3fba106 --- /dev/null +++ b/bb.txt @@ -0,0 +1,35 @@ +package MatrixExpression; + +import MatrixExpression.MyAdjGraphic; +import MatrixExpression.Weight; + +public class MatrixExpression { + + public static void main(String[] args) { + + int n=5; + int e=5; + + MyAdjGraphic g = new MyAdjGraphic(n); + Object[] vertices = new Object[]{new Character('A'),new Character('B'),new Character('C'),new Character('D'),new Character('E')}; + Weight[] weights = new Weight[]{new Weight(0,1,10),new Weight(0,4,20),new Weight(2,1,40),new Weight(1,3,30),new Weight(3,2,50)}; + try + { + Weight.createAdjGraphic(g, vertices, n, weights, e); + System.out.println("领接矩阵:"); + g.print(); + System.out.println("结点的个数:"+g.getNumOfVertice()); + System.out.println("边的个数:"+g.getNumOfEdges()); + g.deleteEdges(0, 4); + System.out.println("删除:"); + g.print(); + System.out.println("结点的个数:"+g.getNumOfVertice()); + System.out.println("边的个数:"+g.getNumOfEdges()); + } + catch(Exception ex) + { + + } + } + +} \ No newline at end of file -- Gitee From 66d406eff60e4a92595edf49d56d70fd99e02c20 Mon Sep 17 00:00:00 2001 From: ssp <245492694@qq.com> Date: Thu, 7 Jan 2021 18:29:49 +0800 Subject: [PATCH 6/7] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vv.txt | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 vv.txt diff --git a/vv.txt b/vv.txt new file mode 100644 index 0000000..e6be51b --- /dev/null +++ b/vv.txt @@ -0,0 +1,29 @@ +package MatrixExpression; +public class Weight { + + int row; + int col; + int weight; + + Weight(int row,int col,int weight) + { + this.row = row; + this.col = col; + this.weight = weight; + } + + public static void createAdjGraphic(MyAdjGraphic g, Object[] vertices, int n,Weight[] weight,int e) + throws Exception + { + + for(int i=0;i Date: Thu, 7 Jan 2021 18:30:15 +0800 Subject: [PATCH 7/7] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zz.txt | 148 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 zz.txt diff --git a/zz.txt b/zz.txt new file mode 100644 index 0000000..40dad8e --- /dev/null +++ b/zz.txt @@ -0,0 +1,148 @@ +package Traversal; + +public class T { + private char[] mVexs; + private int[][] mMatrix; + public T(char[] vexs, char[][] edges){ + int vlen=vexs.length; + int elen=edges.length; + mVexs=new char[vlen]; + for(int i=0;i=0){ + if(visited[k]==false){ + visited[k]=true; + System.out.print(" "+mVexs[k]); + queue[rear++]=k; + } + k=nextVertex(j,k); + } + } + } + + + } + private void DFS() { + boolean[] visited=new boolean[mVexs.length]; + System.out.println("DFS:"); + for(int i=0;i=0){ + if(visited[w]==false){ + DFS(w,visited); + } + w=nextVertex(i,w); + } + i--; + } +} \ No newline at end of file -- Gitee