Skip to content
Snippets Groups Projects
Commit c1f7da54 authored by Peter Wagenhuber's avatar Peter Wagenhuber
Browse files

immer noch keinen pfad gefunden

parent 80f7145e
Branches
No related tags found
No related merge requests found
No preview for this file type
No preview for this file type
File added
package nloc; package nloc;
import java.util.List;
import java.util.ArrayList;
import java.util.Stack;
public class Nloc { public class Nloc {
public static void main(String[] args) { public static void main(String[] args) {
Channel chan0 = new Channel(6,6); Channel chan0 = new Channel(6,6);
...@@ -34,7 +38,15 @@ public class Nloc { ...@@ -34,7 +38,15 @@ public class Nloc {
m0.addChild(chan6); m0.addChild(chan6);
chan6.addChild(chan7); chan6.addChild(chan7);
printPath(p0); getAllPaths(p0);
//List<Path> pl = new ArrayList<Path>();
//printAllPaths(p0,new Path(), pl);
//System.out.println(pl);
//for (Path p : pl) {
// for (Channel ch : p.getChanlist()) {
// System.out.println("ID: " + ch.getID());
// }
//}
// for(Channel ch : chan0.getChildren()) { // for(Channel ch : chan0.getChildren()) {
...@@ -45,7 +57,7 @@ public class Nloc { ...@@ -45,7 +57,7 @@ public class Nloc {
// } // }
// for(Channel ch : chan2.getChildren()) { // for(Channel ch : chan2.getChildren()) {
// System.out.println("ID: " + ch.getID() + " pSteps: " + ch.getPSteps()); // System.out.println("ID: " + ch.getID() + " pSteps: " + ch.getPSteps());
// } // }
} }
// list nodes_to_visit = {root}; // list nodes_to_visit = {root};
// while( nodes_to_visit isn't empty ) { // while( nodes_to_visit isn't empty ) {
...@@ -53,6 +65,56 @@ public class Nloc { ...@@ -53,6 +65,56 @@ public class Nloc {
// nodes_to_visit.prepend( currentnode.children ); // nodes_to_visit.prepend( currentnode.children );
// //do something // //do something
// } // }
//
//stack.push(root)
//while !stack.isEmpty() do
// node = stack.pop()
// for each node.childNodes do
// stack.push(stack)
// endfor
// // …
//endwhile
public static void getAllPaths(Channel chan) {
Path p = new Path();
List<Path> pl = new ArrayList<Path>();
Stack<Channel> chanStack = new Stack<Channel>();
chanStack.push(chan);
while(!chanStack.empty()) {
Channel temp = chanStack.pop();
System.out.println("path add: " + temp.getID());
p.add(temp);
if (temp.getChildren().size() == 0) {
System.out.println(chanStack);
for (Channel c : p.getChanlist()) {
System.out.println( c + ": " + c.getID());
}
}
for (Channel chl : temp.getChildren()) {
System.out.println("stack push " + chl.getID());
System.out.println(chanStack);
chanStack.push(chl);
}
}
}
public static void printAllPaths(Channel chan, Path path, List<Path> pathlist) {
path.add(chan);
if (chan.getChildren().size() == 0) {
System.out.println("Here" );
for (Channel ch : path.getChanlist()) {
System.out.print(ch.getID() + " ; ");
}
System.out.println( "");
pathlist.add(path);
} else {
for (Channel ch : chan.getChildren()) {
printAllPaths(ch, new Path(path), pathlist);
}
}
}
public static void printPath(Channel chan) { public static void printPath(Channel chan) {
System.out.println("ID: " + chan.getID() + " pSteps: " + chan.getPSteps()); System.out.println("ID: " + chan.getID() + " pSteps: " + chan.getPSteps());
if (chan.getChildren().size() != 0) { if (chan.getChildren().size() != 0) {
......
package nloc;
import java.util.List;
import java.util.LinkedList;
public class Path {
private List<Channel> path;
public Path (List<Channel> path) {
this.path = path;
}
public Path (Path p) {
this.path = new LinkedList<Channel>(p.getChanlist());
}
public Path () {
this.path = new LinkedList<Channel>();
}
public void add(Channel chan) {
path.add(chan);
}
public List<Channel> getChanlist() {
return path;
}
public Channel pollLast() {
return path.pollLast();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment