Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Nov 28, 2007, 02:02 PM   #1
dvince2
macrumors 6502
 
Join Date: Mar 2007
Location: Canada
Java DFS find path

hey everyone!
quick question.

I've been working on this for several days now, and I can't seem to find whats wrong. I'm attempting to write a (recursive) method to for findPath using DFS. Its supposed to return an iterator over the verticies on the path. S is an instance variable of type Stack<Vertex<V>>

My code presently compiles and runs a few recursions, then usually crashes. any suggestions? Thanks in advance!

here is what I have:

public Iterator<Vertex<V>> givePath(Graph<V> g, Vertex<V> v, Vertex<V> z){

Iterator<Vertex<V>>result=null;;

System.out.println("Object:" + v.getObject().toString()+" size S: "+S.size()) ;

v.setMarker(true);
this.S.push(v);

if(v==z){
return this.S.iterator();
}

Iterator <Edge<V>>incidentEdges= v.incidentEdges();
Vertex<V> w;
Edge<V> e;
while(incidentEdges.hasNext()){
e=incidentEdges.next();

w = g.giveOpposite(v, e);
if(!w.getMarker()){
result=givePath(g,w,z);

if(result!=null){
return result;
}
}
}

this.S.pop();
return null;

}
dvince2 is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Java Applet not working on Lion jake4ever Mac OS X 10.7 Lion 19 Feb 1, 2013 09:44 AM
Library path errors after Apple software update. Alan S MacBook Pro 1 Aug 22, 2011 08:11 PM
Using accessors in Java constructors (marc) Mac Programming 4 Dec 3, 2010 09:37 AM
Small Java Problem finnschi Mac Programming 9 Nov 25, 2010 04:26 PM
Simple Java help finding the difference in two integer objects cx300 Mac Programming 8 Feb 6, 2009 05:59 PM


All times are GMT -5. The time now is 12:10 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC