Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
2XB3FinalProject
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Christopher Schankula
2XB3FinalProject
Commits
8a7810f2
Commit
8a7810f2
authored
7 years ago
by
Lawrence Chung
Browse files
Options
Downloads
Patches
Plain Diff
make CC, edit Fish iterator
parent
e7409ea8
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/search/CC.java
+50
-0
50 additions, 0 deletions
src/search/CC.java
src/search/Fish.java
+17
-2
17 additions, 2 deletions
src/search/Fish.java
with
67 additions
and
2 deletions
src/search/CC.java
0 → 100644
+
50
−
0
View file @
8a7810f2
package
search
;
public
class
CC
{
private
boolean
[]
marked
;
private
int
[]
id
;
private
int
count
;
public
static
void
main
(
String
[]
args
)
{
Graph
g
=
new
Graph
(
5
);
g
.
addEdge
(
4
,
3
);
g
.
addEdge
(
2
,
3
);
g
.
addEdge
(
1
,
2
);
g
.
addEdge
(
0
,
2
);
CC
component
=
new
CC
(
g
);
System
.
out
.
println
(
component
.
connected
(
0
,
2
));
}
public
CC
(
Graph
G
){
marked
=
new
boolean
[
G
.
V
()];
id
=
new
int
[
G
.
V
()];
for
(
int
s
=
0
;
s
<
G
.
V
();
s
++){
if
(!
marked
[
s
]){
dfs
(
G
,
s
);
count
++;
}
}
}
private
void
dfs
(
Graph
G
,
int
v
){
marked
[
v
]
=
true
;
id
[
v
]
=
count
;
for
(
int
w
:
G
.
adj
(
v
)){
if
(!
marked
[
w
])
dfs
(
G
,
w
);
}
}
public
boolean
connected
(
int
v
,
int
w
){
return
id
[
v
]
==
id
[
w
];
}
public
int
id
(
int
v
){
return
id
[
v
];
}
public
int
count
(){
return
count
;
}
}
This diff is collapsed.
Click to expand it.
src/search/Fish.java
+
17
−
2
View file @
8a7810f2
...
...
@@ -20,8 +20,23 @@ public class Fish<Integer> implements Iterable<Integer> {
@Override
public
Iterator
<
Integer
>
iterator
()
{
// TODO Auto-generated method stub
return
null
;
return
new
ListIterator
();
}
private
class
ListIterator
implements
Iterator
<
Integer
>{
private
Node
current
=
first
;
public
boolean
hasNext
(){
return
current
!=
null
;
}
public
Integer
next
(){
Integer
item
=
current
.
item
;
current
=
current
.
next
;
return
item
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment