Skip to content

Commit 4decb83

Browse files
committed
commit
1 parent 2082eb1 commit 4decb83

File tree

92 files changed

+4466
-32
lines changed

Some content is hidden

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

92 files changed

+4466
-32
lines changed

.metadata/.log

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,3 +319,49 @@ Java Model Exception: Java Model Status [Timed out while retrieving the attached
319319
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
320320
!SUBENTRY 1 org.eclipse.jdt.core 4 1012 2017-09-30 15:51:36.800
321321
!MESSAGE Timed out while retrieving the attached javadoc for ArrayList [in ArrayList.class [in java.util [in /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/rt.jar]]]
322+
!SESSION 2017-10-02 09:59:26.304 -----------------------------------------------
323+
eclipse.buildId=debbuild
324+
java.version=1.7.0_131
325+
java.vendor=Oracle Corporation
326+
BootLoader constants: OS=linux, ARCH=x86_64, WS=gtk, NL=zh_CN
327+
Command-line arguments: -os linux -ws gtk -arch x86_64
328+
329+
!ENTRY org.eclipse.core.resources 2 10035 2017-10-02 09:59:32.805
330+
!MESSAGE The workspace exited with unsaved changes in the previous session; refreshing workspace to recover changes.
331+
332+
!ENTRY org.eclipse.ui 4 0 2017-10-02 10:11:33.870
333+
!MESSAGE Unhandled event loop exception
334+
!STACK 0
335+
java.lang.IllegalArgumentException: Argument cannot be null
336+
at org.eclipse.swt.SWT.error(SWT.java:4342)
337+
at org.eclipse.swt.SWT.error(SWT.java:4276)
338+
at org.eclipse.swt.SWT.error(SWT.java:4247)
339+
at org.eclipse.swt.widgets.Widget.error(Widget.java:480)
340+
at org.eclipse.swt.widgets.Control.removeMouseMoveListener(Control.java:1989)
341+
at org.eclipse.jface.text.AbstractInformationControl$5.mouseUp(AbstractInformationControl.java:403)
342+
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:220)
343+
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
344+
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1276)
345+
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3562)
346+
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3186)
347+
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2701)
348+
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2665)
349+
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2499)
350+
at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:679)
351+
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
352+
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:668)
353+
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
354+
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:124)
355+
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
356+
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
357+
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
358+
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:353)
359+
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)
360+
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
361+
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
362+
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
363+
at java.lang.reflect.Method.invoke(Method.java:606)
364+
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)
365+
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)
366+
at org.eclipse.equinox.launcher.Main.run(Main.java:1438)
367+
at org.eclipse.equinox.launcher.Main.main(Main.java:1414)
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
package class02;
2+
3+
import java.io.InputStream;
4+
import java.util.ArrayList;
5+
import java.util.List;
6+
import java.util.Queue;
7+
import java.util.Scanner;
8+
9+
import RepresentationGraph.Graph.Node;
10+
11+
12+
13+
/**
14+
* 广度优先搜索:第22章第二节
15+
* @author liyafei
16+
*
17+
*/
18+
public class BFS {
19+
List q=new ArrayList<>();
20+
List list=new ArrayList();
21+
22+
23+
public void printPath(int s,int v){
24+
System.out.println(list.size());
25+
Node sn=(Node) list.get(s);
26+
Node vn=(Node) list.get(v);
27+
if(s==v){
28+
System.out.println(s);
29+
}else if(vn.pre==null){
30+
System.out.println("no path from "+s+" to "+v+" exists");
31+
}else{
32+
printPath(s, vn.pre.key);
33+
System.out.println(v);
34+
}
35+
}
36+
37+
/**
38+
* 广度优先搜索,给定节点,搜索路径
39+
* @param vertex 给定的节点
40+
*/
41+
public void breadthFirstSearch(int vertex){
42+
for (int i = 0; i < list.size(); i++) {
43+
if(i!=vertex){
44+
Node node=(Node) list.get(i);
45+
node.color="WHITE";
46+
node.d=Double.MAX_VALUE;
47+
node.pre=null;
48+
}
49+
}
50+
51+
Node s=(Node) list.get(vertex);
52+
s.color="GRAY";
53+
s.d=0;
54+
s.pre=null;
55+
56+
q.add(s);
57+
58+
while(q.size()!=0){
59+
Node u=(Node) q.remove(0);
60+
int length=getLength(u);
61+
for (int i = 0; i < length; i++) {
62+
Node v = null;
63+
v=u;
64+
for (int j = 0; j <= i; j++) {
65+
v=v.link;
66+
}
67+
System.out.println(v.key);
68+
if((v.color).equals("WHITE")){
69+
v.color="GRAY";
70+
v.d=u.d+1;
71+
v.pre=u;
72+
q.add(v);
73+
}
74+
}
75+
System.out.println(q.size());
76+
u.color="BLACK";
77+
}
78+
}
79+
80+
/**
81+
* 图节点
82+
* @author liyafei
83+
*
84+
*/
85+
public class Node{
86+
Node pre; //前驱节点
87+
Node link;
88+
int key;
89+
String color="WHITE";
90+
double d=0;
91+
}
92+
93+
/**
94+
* 创建图,以链表的方式创建图
95+
* @return 返回图的链表形式,其中数组中每个位置是一个顶点的链表
96+
*/
97+
// public Node[] createGraph(){
98+
public List createGraph(){
99+
Class clazz=this.getClass();
100+
InputStream ins=clazz.getResourceAsStream("/data1.txt"); //通过外部数据创建链表,使用/加载src目录下的文件
101+
//不使用/是加载类路径下的文件
102+
Scanner scanner=new Scanner(ins); //流输入。
103+
while(scanner.hasNextLine()){
104+
String s=scanner.nextLine();
105+
Scanner oneLine=new Scanner(s);
106+
Node first=null;
107+
Node newNode,last=null;
108+
while(oneLine.hasNext()){
109+
String s1=oneLine.next();
110+
int num=Integer.parseInt(s1);
111+
if(num==999)
112+
break;
113+
newNode=new Node();
114+
newNode.key=num;
115+
newNode.link=null;
116+
if(first ==null){
117+
first=newNode;
118+
last=newNode;
119+
}else{
120+
last.link=newNode;
121+
last=newNode;
122+
}
123+
}
124+
list.add(first);
125+
}
126+
return list;
127+
}
128+
129+
/**
130+
* 打印图中某个指定节点链表的长度
131+
* @param node 需要求长度的节点
132+
* @return 节点的长度
133+
*/
134+
public int getLength(Node node){
135+
int length=0;
136+
while(node.link!=null){
137+
node=node.link;
138+
length++;
139+
}
140+
return length;
141+
}
142+
143+
/**
144+
* 打印图
145+
*/
146+
public void printGraph(){
147+
for (int i = 0; i < list.size(); i++) {
148+
149+
Node first=(Node) list.get(i);
150+
if(first==null){
151+
break;
152+
}
153+
System.out.println("打印了第"+(i+1)+"个节点的数据");
154+
while(first!=null){
155+
System.out.print(first.key+" ");
156+
first=first.link;
157+
}
158+
System.out.println("");
159+
}
160+
}
161+
162+
}
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
package class02;
2+
3+
import java.io.InputStream;
4+
import java.util.ArrayList;
5+
import java.util.List;
6+
import java.util.Queue;
7+
import java.util.Scanner;
8+
9+
import RepresentationGraph.Graph.Node;
10+
11+
12+
13+
/**
14+
* 广度优先搜索:第22章第二节
15+
* @author liyafei
16+
*
17+
*/
18+
public class BFS {
19+
List q=new ArrayList<>();
20+
List list=new ArrayList();
21+
boolean[] nodeFound=new boolean[list.size()];
22+
23+
public void printPath(int s,int v){
24+
System.out.println(list.size());
25+
Node sn=(Node) list.get(s);
26+
Node vn=(Node) list.get(v);
27+
if(s==v){
28+
System.out.println(s);
29+
}else if(vn.pre==null){
30+
System.out.println("no path from "+s+" to "+v+" exists");
31+
}else{
32+
printPath(s, vn.pre.key);
33+
System.out.println(v);
34+
}
35+
}
36+
37+
/**
38+
* 广度优先搜索,给定节点,搜索路径
39+
* @param vertex 给定的节点
40+
*/
41+
public void breadthFirstSearch(int vertex){
42+
for (int i = 0; i < list.size(); i++) {
43+
if(i!=vertex){
44+
Node node=(Node) list.get(i);
45+
node.color="WHITE";
46+
node.d=Double.MAX_VALUE;
47+
node.pre=null;
48+
nodeFound[i]=false;
49+
}else{
50+
nodeFound[i]=true;
51+
}
52+
}
53+
54+
Node s=(Node) list.get(vertex);
55+
s.color="GRAY";
56+
s.d=0;
57+
s.pre=null;
58+
59+
q.add(s);
60+
61+
while(q.size()!=0){
62+
Node u=(Node) q.remove(0);
63+
int length=getLength(u);
64+
for (int i = 0; i < length; i++) {
65+
Node v = null;
66+
v=u;
67+
for (int j = 0; j <= i; j++) {
68+
v=v.link;
69+
}
70+
if((v.color).equals("WHITE")){
71+
v.color="GRAY";
72+
v.d=u.d+1;
73+
v.pre=u;
74+
q.add(v);
75+
}
76+
}
77+
System.out.println(q.size());
78+
u.color="BLACK";
79+
}
80+
}
81+
82+
/**
83+
* 图节点
84+
* @author liyafei
85+
*
86+
*/
87+
public class Node{
88+
Node pre; //前驱节点
89+
Node link;
90+
int key;
91+
String color="WHITE";
92+
double d=0;
93+
}
94+
95+
/**
96+
* 创建图,以链表的方式创建图
97+
* @return 返回图的链表形式,其中数组中每个位置是一个顶点的链表
98+
*/
99+
// public Node[] createGraph(){
100+
public List createGraph(){
101+
Class clazz=this.getClass();
102+
InputStream ins=clazz.getResourceAsStream("/data1.txt"); //通过外部数据创建链表,使用/加载src目录下的文件
103+
//不使用/是加载类路径下的文件
104+
Scanner scanner=new Scanner(ins); //流输入。
105+
while(scanner.hasNextLine()){
106+
String s=scanner.nextLine();
107+
Scanner oneLine=new Scanner(s);
108+
Node first=null;
109+
Node newNode,last=null;
110+
while(oneLine.hasNext()){
111+
String s1=oneLine.next();
112+
int num=Integer.parseInt(s1);
113+
if(num==999)
114+
break;
115+
newNode=new Node();
116+
newNode.key=num;
117+
newNode.link=null;
118+
if(first ==null){
119+
first=newNode;
120+
last=newNode;
121+
}else{
122+
last.link=newNode;
123+
last=newNode;
124+
}
125+
}
126+
list.add(first);
127+
}
128+
return list;
129+
}
130+
131+
/**
132+
* 打印图中某个指定节点链表的长度
133+
* @param node 需要求长度的节点
134+
* @return 节点的长度
135+
*/
136+
public int getLength(Node node){
137+
int length=0;
138+
while(node.link!=null){
139+
node=node.link;
140+
length++;
141+
}
142+
return length;
143+
}
144+
145+
/**
146+
* 打印图
147+
*/
148+
public void printGraph(){
149+
for (int i = 0; i < list.size(); i++) {
150+
151+
Node first=(Node) list.get(i);
152+
if(first==null){
153+
break;
154+
}
155+
System.out.println("打印了第"+(i+1)+"个节点的数据");
156+
while(first!=null){
157+
System.out.print(first.key+" ");
158+
first=first.link;
159+
}
160+
System.out.println("");
161+
}
162+
}
163+
164+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package class02;
2+
3+
public class TestBFS {
4+
5+
public static void main(String[] args) {
6+
BFS bfs=new BFS();
7+
bfs.createGraph();
8+
// bfs.printGraph();
9+
bfs.breadthFirstSearch(1);
10+
bfs.printPath(1,2);
11+
}
12+
}

0 commit comments

Comments
 (0)