import [Link].
ArrayList;
import [Link];
public class Graph {
private List<Integer> nodes;
private int[][] graph;
private int node_count;
public Graph() {
nodes = new ArrayList<>();
graph = new int[0][0];
node_count = 0;
}
public void add_node(int v) {
if ([Link](v)) {
[Link](v + " is already present in the graph");
} else {
node_count++;
[Link](v);
[Link](node_count+" value :-->"+v);
int[][] newGraph = new int[node_count][node_count];
for (int i = 0; i < node_count - 1; i++) {
[Link](graph[i], 0, newGraph[i], 0, node_count - 1);
}
graph = newGraph;
}
}
public void add_edge(int v1, int v2) {
if () {
[Link](v1 + " is not present in graph");
} else if () {
[Link](v2 + " is not present in the graph");
} else {
int index1 = [Link](v1);
int index2 = [Link](v2);
graph[index1][index2] = 1;
graph[index2][index1] = 1;
}
}
public void delete_edge(int v1,int v2)
{
int index1 = [Link](v1);
int index2 = [Link](v2);
graph[index1][index2] = 0;
graph[index2][index1] = 0;
}
public void print_graph() {
for (int i = 0; i < node_count; i++) {
for (int j = 0; j < node_count; j++) {
[Link]("%-3d", graph[i][j]);
}
[Link]();
}
}
public static void main(String[] args) {
Graph graph = new Graph();
graph.add_node(1);
graph.add_node(3);
graph.add_node(3);
graph.add_node(1);
graph.add_node(4);
graph.add_edge(1, 2);
graph.add_edge(4, 3);
graph.add_edge(4, 1);
graph.print_graph();
graph.delete_edge(4,1);
[Link]("After Deletion :");
graph.print_graph();
}
}