file management

This commit is contained in:
DarianTr
2023-11-16 16:03:51 +01:00
parent fbb278c5d9
commit d5d9994f18
6 changed files with 140 additions and 164 deletions

View File

@@ -0,0 +1,53 @@
class Graph {
ArrayList<ArrayList<Integer>> adj;
ArrayList<ArrayList<Integer>> coords;
int V;
Graph(int v) {
V = v;
adj = new ArrayList<ArrayList<Integer>>(V);
coords = new ArrayList<ArrayList<Integer>>(V);
for (int i = 0; i < V; i++) {
adj.add(new ArrayList<Integer>());
coords.add(new ArrayList<Integer>());
}
}
void draw_vis(boolean[] vis) {
strokeWeight(20);
stroke(255);
for (int i = 0; i < coords.size(); i++) {
if (!vis[i]) continue;
point(coords.get(i).get(0), coords.get(i).get(1));
text(i+1, coords.get(i).get(0)-4, coords.get(i).get(1)+5);
}
}
void draw_points(int point_weight) {
strokeWeight(point_weight);
stroke(#FF0000);
for (int i = 0; i < coords.size(); i++) {
point(coords.get(i).get(0), coords.get(i).get(1));
text(i+1, coords.get(i).get(0)-3, coords.get(i).get(1)+5);
}
}
void draw_graph(int graph_weight, int point_weight) {
stroke(#550000);
strokeWeight(10);
for (int i = 0; i < adj.size(); i++) {
for (int idx = 0; idx < adj.get(i).size(); idx++) {
int e = adj.get(i).get(idx);
draw_arrow(coords.get(i).get(0), coords.get(i).get(1), coords.get(e).get(0), coords.get(e).get(1), point_weight, graph_weight);
}
}
}
void set_coords(int idx, int x, int y) {
coords.get(idx).add(x);
coords.get(idx).add(y);
}
void add_edge(int u, int v) {
adj.get(u).add(v);
}
}