-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathGraphMatrice.java
More file actions
51 lines (46 loc) · 1.37 KB
/
GraphMatrice.java
File metadata and controls
51 lines (46 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Created by sidhant
//28/03/2017
//Basic Grapgh implementation to add and delete edges between the vertices using DDA
import java.util.*;
public class Graph_implementatn
{
public static void main (String args[])
{
Scanner in=new Scanner (System.in);
System.out.println("Enter number of vertices");
int n=in.nextInt();
int a[][]=new int [n][n];
while (true)
{
System.out.println("1:insertion");
System.out.println("2:removal");
System.out.println("3:print");
int d=in.nextInt();
if (d==1)
{
System.out.println("Enter pair of vertices to form edge");
int x=in.nextInt();
int y=in.nextInt();
a[x-1][y-1]=1;
a[y-1][x-1]=1;
}
if (d==2)
{
System.out.println("Enter pair of vertices to remove edge");
int x=in.nextInt();
int y=in.nextInt();
a[x-1][y-1]=0;
a[y-1][x-1]=0;
}
if (d==3)
{
for (int i=0;i<n;i++)
{
for (int j=0;j<n;j++)
System.out.print(a[i][j]);
System.out.println();
}
}
}
}
}