Skip to content

Commit 7dbd64e

Browse files
committed
commit
1 parent b73d6d6 commit 7dbd64e

File tree

41 files changed

+159
-5
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+159
-5
lines changed

.metadata/.log

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,12 @@ Command-line arguments: -os linux -ws gtk -arch x86_64
197197

198198
!ENTRY org.eclipse.core.resources 2 10035 2017-09-29 18:02:39.094
199199
!MESSAGE The workspace exited with unsaved changes in the previous session; refreshing workspace to recover changes.
200+
!SESSION 2017-09-29 21:20:56.179 -----------------------------------------------
201+
eclipse.buildId=debbuild
202+
java.version=1.7.0_131
203+
java.vendor=Oracle Corporation
204+
BootLoader constants: OS=linux, ARCH=x86_64, WS=gtk, NL=zh_CN
205+
Command-line arguments: -os linux -ws gtk -arch x86_64
206+
207+
!ENTRY org.eclipse.core.resources 2 10035 2017-09-29 21:21:02.730
208+
!MESSAGE The workspace exited with unsaved changes in the previous session; refreshing workspace to recover changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package breadth_first_search;
2+
3+
public class BreadthFirstSearch {
4+
5+
}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
package RepresentationGraph;
2+
3+
import java.io.InputStream;
4+
import java.util.ArrayList;
5+
import java.util.List;
6+
import java.util.Scanner;
7+
8+
/**
9+
* 图结构
10+
* @author liyafei
11+
*
12+
* @param <T> 泛型
13+
*/
14+
public class Graph{
15+
16+
protected Node[] graph; //以数组的方式存储图,需要初始化指定数组的长度
17+
protected List<Node> list=new ArrayList<Node>(); //以数组列表的形式存放图,可以不用初始化,直接添加
18+
protected int maxSize;
19+
protected int gSize;
20+
public int count=0;
21+
public Graph(int maxSize,int gSize){
22+
this.maxSize=maxSize;
23+
this.gSize=gSize;
24+
graph=new Node[maxSize];
25+
}
26+
/**
27+
*图中的节点
28+
* @author liyafei
29+
*
30+
* @param <> 节点中的泛型
31+
*/
32+
public class Node{
33+
Node link;
34+
int key;
35+
}
36+
37+
/**
38+
* 清空图
39+
*/
40+
public void clearGraph(){
41+
for (int index = 0; index < graph.length; index++) {
42+
graph[index]=null;
43+
}
44+
}
45+
46+
/**
47+
* 创建图,以链表的方式创建图
48+
* @return 返回图的链表形式,其中数组中每个位置是一个顶点的链表
49+
*/
50+
// public Node[] createGraph(){
51+
public List createGraph(){
52+
Class clazz=this.getClass();
53+
InputStream ins=clazz.getResourceAsStream("/data.txt"); //通过外部数据创建链表,使用/加载src目录下的文件
54+
//不使用/是加载类路径下的文件
55+
Scanner scanner=new Scanner(ins); //流输入。
56+
while(scanner.hasNextLine()){
57+
String s=scanner.nextLine();
58+
Scanner oneLine=new Scanner(s);
59+
Node first=null;
60+
Node newNode,last=null;
61+
while(oneLine.hasNext()){
62+
String s1=oneLine.next();
63+
int num=Integer.parseInt(s1);
64+
if(num==999)
65+
break;
66+
newNode=new Node();
67+
newNode.key=num;
68+
newNode.link=null;
69+
if(first ==null){
70+
first=newNode;
71+
last=newNode;
72+
}else{
73+
last.link=newNode;
74+
last=newNode;
75+
}
76+
}
77+
graph[count]=first;
78+
list.add(first);
79+
count++;
80+
}
81+
return list;
82+
}
83+
84+
/**
85+
* 打印图中某个指定节点链表的长度
86+
* @param node 需要求长度的节点
87+
* @return 节点的长度
88+
*/
89+
public int getLength(Node node){
90+
int length=0;
91+
while(node.link!=null){
92+
node=node.link;
93+
length++;
94+
}
95+
return length;
96+
}
97+
98+
/**
99+
* 打印图,以数组列表的形式存储链表,构成图
100+
*/
101+
public void printGraph(){
102+
for (int i = 0; i < list.size(); i++) {
103+
104+
Node first=(Node) list.get(i);
105+
if(first==null){
106+
break;
107+
}
108+
System.out.println("打印了第"+(i+1)+"个节点的数据");
109+
while(first!=null){
110+
System.out.print(first.key);
111+
first=first.link;
112+
}
113+
System.out.println("");
114+
}
115+
}
116+
}

.metadata/.plugins/org.eclipse.core.resources/.history/e7/60f78ce60fa50017166aec101a9d3889

Whitespace-only changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)