Przeglądaj źródła

add specification of Graph class and Stack class.

171870002 5 lat temu
rodzic
commit
8d9aba95d0

+ 75 - 0
src/main/java/com/example/data_structure/domain/Graph.java

@@ -1,4 +1,79 @@
 package com.example.data_structure.domain;
 
+import java.util.ArrayList;
+
 public class Graph {
+    private boolean isDirected; //是否有向
+    private boolean isWeighted; //是否带权
+    private int nodeNum; //结点数
+    private int edgeNum;//边数
+    private ArrayList<String> nodeList; //各结点名称
+    private ArrayList<ArrayList<Boolean>> graph; //图中结点和边的连接关系
+    private ArrayList<ArrayList<Double>>weight;//各边权重
+
+
+    /**
+     * 没有权重的图的构造方法
+     * @param isDirected
+     * @param nodeNum
+     * @param edgeNum
+     * @param nodeList
+     * @param graph
+     */
+    public Graph(boolean isDirected, int nodeNum, int edgeNum, ArrayList<String> nodeList, ArrayList<ArrayList<Boolean>> graph) {
+        this.isDirected = isDirected;
+        this.isWeighted=false;
+        this.nodeNum = nodeNum;
+        this.edgeNum = edgeNum;
+        this.nodeList = nodeList;
+        this.graph = graph;
+        this.weight=null;
+    }
+
+    /**
+     * 带权图构造方法
+     * @param isDirected
+     * @param isWeighted
+     * @param nodeNum
+     * @param edgeNum
+     * @param nodeList
+     * @param graph
+     * @param weight
+     */
+    public Graph(boolean isDirected, boolean isWeighted, int nodeNum, int edgeNum, ArrayList<String> nodeList, ArrayList<ArrayList<Boolean>> graph, ArrayList<ArrayList<Double>> weight) {
+        this.isDirected = isDirected;
+        this.isWeighted = isWeighted;
+        this.nodeNum = nodeNum;
+        this.edgeNum = edgeNum;
+        this.nodeList = nodeList;
+        this.graph = graph;
+        this.weight = weight;
+    }
+
+
+    /**
+     * 获取计算最小生成树过程中每一步的结果,返回一个结果列表
+     * @return
+     */
+    public ArrayList<Graph> getMinimalSpanningTree(){
+
+        return null;
+    }
+
+    /**
+     * 获取广度优先遍历的结点遍历顺序
+     * @return
+     */
+    public ArrayList<String> getBreadthFirstTraversal(){
+        return null;
+    }
+
+    /**
+     * 获取深度优先遍历的结点遍历顺序
+     * @return
+     */
+    public ArrayList<String> getDepthFirstTraversal(){
+        return null;
+    }
+
 }

+ 63 - 0
src/main/java/com/example/data_structure/domain/Stack.java

@@ -1,4 +1,67 @@
 package com.example.data_structure.domain;
 
+import java.util.ArrayList;
+
 public class Stack {
+
+    public static final int MAX_SIZE =20;
+    private int capacity; //栈的最大容量
+    private int size; //栈现有的元素数
+    private String elementType; //栈元素的类型,有char,String,int,double四种类型
+    private ArrayList<Object> content;
+
+    /**
+     * 全参数构造方法
+     * @param capacity
+     * @param size
+     * @param elementType
+     * @param content
+     */
+    public Stack(int capacity, int size, String elementType, ArrayList<Object> content) {
+        this.capacity = capacity;
+        this.size = size;
+        this.elementType = elementType;
+        this.content = content;
+    }
+
+    /**
+     * 不指定最大容量的构造方法
+     * @param size
+     * @param elementType
+     * @param content
+     */
+    public Stack(int size, String elementType, ArrayList<Object> content) {
+        this.size = size;
+        this.elementType = elementType;
+        this.content = content;
+    }
+
+
+    private boolean isFull(){
+        return false;
+    }
+    private boolean isEmpty(){
+        return true;
+    }
+
+    /**
+     * push操作成功返回true,否则返回false
+     * @return
+     */
+    public boolean push(){
+        return false;
+    }
+
+    /**
+     * pop()操作成功返回true,否则返回false
+     * @return
+     */
+    public boolean pop(){
+        return false;
+    }
+    
+    public void makeEmpty(){
+
+    }
+
 }