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

Similar Threads
thread Thread Starter Forum Replies Last Post
Can't find Java in System Preferences Jimmy Carozza Mac Basics and Help 6 May 26, 2014 10:55 AM
Chrome on OS X -- Java plugin / Java 7 vs Java 6 Issue booyahbooyah Mac Applications and Mac App Store 4 May 31, 2013 09:13 AM
Find iWork Pages path mctavish Mac Applications and Mac App Store 2 Nov 10, 2012 12:43 AM
Office 2011, saving files to DFS-R server (SMB) andrewgauger Mac Applications and Mac App Store 0 Jun 25, 2012 12:55 PM
How to find and edit the PATH file V6Pony Mac Programming 3 Jun 17, 2012 10:38 AM

Forum Jump

All times are GMT -5. The time now is 03:48 PM.

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

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