Skip to content

Commit b73d6d6

Browse files
committed
commit
1 parent bf2e7d6 commit b73d6d6

File tree

115 files changed

+2817
-8
lines changed

Some content is hidden

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

115 files changed

+2817
-8
lines changed

.metadata/.log

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,3 +188,12 @@ Java Model Exception: Java Model Status [Timed out while retrieving the attached
188188
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
189189
!SUBENTRY 1 org.eclipse.jdt.core 4 1012 2017-09-28 19:39:32.486
190190
!MESSAGE Timed out while retrieving the attached javadoc for Object [in Object.class [in java.lang [in /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/rt.jar]]]
191+
!SESSION 2017-09-29 18:02:32.641 -----------------------------------------------
192+
eclipse.buildId=debbuild
193+
java.version=1.7.0_131
194+
java.vendor=Oracle Corporation
195+
BootLoader constants: OS=linux, ARCH=x86_64, WS=gtk, NL=zh_CN
196+
Command-line arguments: -os linux -ws gtk -arch x86_64
197+
198+
!ENTRY org.eclipse.core.resources 2 10035 2017-09-29 18:02:39.094
199+
!MESSAGE The workspace exited with unsaved changes in the previous session; refreshing workspace to recover changes.
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
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+
public void printGraph(){
99+
for (int i = 0; i < list.size(); i++) {
100+
System.out.println("打印了第"+i+1+"个节点的数据");
101+
Node first=(Node) list.get(i);
102+
if(first==null){
103+
break;
104+
}
105+
while(first!=null){
106+
System.out.print(first.key);
107+
first=first.link;
108+
}
109+
System.out.println("");
110+
}
111+
}
112+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package RepresentationGraph;
2+
3+
import java.io.InputStream;
4+
import java.util.Scanner;
5+
6+
7+
public class Graph<T> {
8+
public Node<T> first,newNode,last;
9+
protected Node<T>[] graph;
10+
protected int maxSize;
11+
protected int gSize;
12+
public int count=0;
13+
public class Node<T>{
14+
Node link;
15+
int key;
16+
}
17+
public Node[] createGraph(){
18+
Class clazz=this.getClass();
19+
InputStream ins=clazz.getResourceAsStream("/data.txt"); //通过外部数据创建链表
20+
Scanner scanner=new Scanner(ins); //流输入。
21+
while(scanner.hasNextLine()){
22+
String s=scanner.nextLine();
23+
Scanner oneLine=new Scanner(s);
24+
25+
while(oneLine.hasNext()){
26+
String s1=oneLine.next();
27+
int num=Integer.parseInt(s1);
28+
if(num==999)
29+
break;
30+
newNode=new Node<T>();
31+
newNode.key=num;
32+
newNode.link=null;
33+
if(first ==null){
34+
first=newNode;
35+
last=newNode;
36+
}else{
37+
last.link=newNode;
38+
last=newNode;
39+
}
40+
}
41+
graph[count]=first;
42+
count++;
43+
}
44+
return graph;
45+
}
46+
47+
48+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package RepresentationGraph;
2+
3+
import java.io.InputStream;
4+
import java.util.Scanner;
5+
6+
/**
7+
* 图结构
8+
* @author liyafei
9+
*
10+
* @param <T> 泛型
11+
*/
12+
public class Graph{
13+
14+
protected Node[] graph;
15+
protected int maxSize;
16+
protected int gSize;
17+
public int count=0;
18+
public Graph(int maxSize,int gSize){
19+
this.maxSize=maxSize;
20+
this.gSize=gSize;
21+
graph=new Node[maxSize];
22+
}
23+
/**
24+
*图中的节点
25+
* @author liyafei
26+
*
27+
* @param <> 节点中的泛型
28+
*/
29+
public class Node{
30+
Node link;
31+
int key;
32+
}
33+
/**
34+
* 创建图,以链表的方式创建图
35+
* @return 返回图的链表形式,其中数组中每个位置是一个顶点的链表
36+
*/
37+
public Node[] createGraph(){
38+
Class clazz=this.getClass();
39+
InputStream ins=clazz.getResourceAsStream("/data.txt"); //通过外部数据创建链表,使用/加载src目录下的文件
40+
//不使用/是加载类路径下的文件
41+
Scanner scanner=new Scanner(ins); //流输入。
42+
while(scanner.hasNextLine()){
43+
String s=scanner.nextLine();
44+
Scanner oneLine=new Scanner(s);
45+
Node first=null;
46+
Node newNode,last=null;
47+
while(oneLine.hasNext()){
48+
String s1=oneLine.next();
49+
System.out.println(s1);
50+
int num=Integer.parseInt(s1);
51+
if(num==999)
52+
break;
53+
newNode=new Node();
54+
newNode.key=num;
55+
newNode.link=null;
56+
if(first ==null){
57+
first=newNode;
58+
last=newNode;
59+
}else{
60+
last.link=newNode;
61+
last=newNode;
62+
}
63+
}
64+
System.out.println(first.key);
65+
graph[count]=first;
66+
count++;
67+
}
68+
return graph;
69+
}
70+
71+
72+
}
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+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package RepresentationGraph;
2+
3+
import RepresentationGraph.Graph.Node;
4+
5+
public class TestGraph {
6+
public static void main(String[] args) {
7+
Graph g=new Graph(100,0);
8+
List graph=g.createGraph();
9+
for (int i = 0; i < graph.length; i++) {
10+
Node first=graph[i];
11+
if(first==null){
12+
break;
13+
}
14+
while(first!=null){
15+
System.out.print(first.key);
16+
first=first.link;
17+
}
18+
System.out.println("");
19+
}
20+
}
21+
}

0 commit comments

Comments
 (0)