Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

graph done #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions nccucs-assignment-2/graph/DijsktraSpecializer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package ps3.graph;
11 changes: 11 additions & 0 deletions nccucs-assignment-2/graph/Edge.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package ps3.graph;
import ps3.graph.WeightedNode;

class Edge{
WeightedNode Begin;
WeightedNode End;
Edge(WeightedNode Begin , WeightedNode End){
this.Begin = Begin;
this.End = End;
}
}
5 changes: 5 additions & 0 deletions nccucs-assignment-2/graph/Graph.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package ps3.graph;

public abstract class Graph{
abstract void AddNode(WeightedNode nd);
}
22 changes: 22 additions & 0 deletions nccucs-assignment-2/graph/NewGraph.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package ps3.graph;
import ps3.graph.Graph;
import ps3.graph.WeightedNode;
import java.util.ArrayList;

public class NewGraph extends Graph{
public String name;
public ArrayList<WeightedNode> nodelist;
public ArrayList<Edge> edgelist;

NewGraph(String name){
this.name = name;
}
void AddNode(WeightedNode nd){
this.nodelist.add(nd);
}
void AddEdge(WeightedNode b,WeightedNode e){
Edge newedge = new Edge(b,e);
this.edgelist.add(newedge);
}

}
52 changes: 52 additions & 0 deletions nccucs-assignment-2/graph/map.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package ps3.graph;
import ps3.graph.WeightedNode;

import java.util.ArrayList;

import ps3.graph.NewGraph;


public class map{
public ArrayList<WeightedNode> node;
public ArrayList<NewGraph> graph;
public map(){

}
public void CreateNode(String n, int c){
WeightedNode nd = new WeightedNode(n,c);
node.add(nd);
}
public void CreateGraph(String n){
NewGraph g = new NewGraph(n);
System.out.println(g.name);
graph.add(g);
}
public void AddNode(String g_n,String n_n){
NewGraph tempgraph = graph.get(graph.indexOf(g_n));
WeightedNode tempnode = node.get(node.indexOf(n_n));
tempgraph.AddNode(tempnode);
}
public void ListNode(String g_n){
NewGraph tempgraph = graph.get(graph.indexOf(g_n));
int size = tempgraph.nodelist.size();
for(int i=0;i<size;i++){
System.out.println(tempgraph.nodelist.get(i).name+" ");
}

}
public void AddEdge(String g_n , String b_n, String e_n){
NewGraph targetgp = graph.get(graph.indexOf(g_n));
WeightedNode beginnd = node.get(node.indexOf(b_n));
WeightedNode endnd = node.get(node.indexOf(e_n));
targetgp.AddEdge(beginnd, endnd);
}
public void ListChild(String g_n, String n_n){
NewGraph targetgp = graph.get(graph.indexOf(g_n));
WeightedNode tempnode = node.get(node.indexOf(n_n));
int edgesize = targetgp.edgelist.size();
for(int i=0;i>edgesize;i++){
if(tempnode.name == targetgp.edgelist.get(i).Begin.name)
System.out.println(targetgp.edgelist.get(i).End.name+" ");
}
}
}
22 changes: 22 additions & 0 deletions nccucs-assignment-2/test./ImplementationTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package ps3.test;

import junit.framework.*;

/**
* ImplementationTest is a test suite used to encapsulate all
* tests specific to your implementation of this problem set.
*
* For instance, unit tests for your individual methods would
* go here.
*/
public final class ImplementationTests extends TestSuite
{
public static Test suite() { return new ImplementationTests(); }
public ImplementationTests() { this("Problem Set 3 ImplementationTests"); }
public ImplementationTests(String s)
{
super(s);

// addTestSuite(MyGreatTests.class);
}
}
Loading