Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Graph {
- public static void main(String args[]) {
- int n; //n-ul va fi preluat de la 'linia de comanda'
- //verificare nr. argumente
- if (args.length > 0)
- n = Integer.parseInt(args[0]);
- //validation n is odd.
- if (n % 2 != 0) {
- System.out.println("That's correct -> n= " + n + ';');
- //create a NxN matrix;
- int[][] adjancecyM = new int[n][n];
- int i, j, random, sum = 0, degreeVertex = 0, degreeMax = 0, degreeMin = 1000000, degreeTotal = 0;
- //G complete
- int[][] graphComplete ( int nrVertex){
- for (i = 0; i < adjancecyM.length; ++i)
- for (j = 0; j < adjancecyM.length; ++j)
- if (i != j) adjancecyM[i][j] = adjancecyM[j][i] = 1;
- System.out.println("Edges: " + (n * (n - 1) / 2));
- }
- /**
- //G cycle
- for (i = 0; i < adjancecyM.length - 1; ++i) {
- adjancecyM[i][i + 1] = 1;
- }
- adjancecyM[adjancecyM.length - 1][0] = 1;
- System.out.println("Edges: " + n);
- //G random
- for (i = 0; i < adjancecyM.length; ++i)
- for (j = 0; j < adjancecyM.length; ++j) {
- if (((int) (Math.random() * 2) == 1) && i != j) {
- adjancecyM[i][j] = 1;
- sum++;
- } else
- adjancecyM[i][j] = 0;
- }
- System.out.println();
- if (sum > 1 && sum % 2 == 1) System.out.println("Edges: " + ((sum + 1) / 2));
- else if (sum > 1 && sum % 2 == 0) System.out.println("Edges: " + sum);
- else
- System.out.println("Graf doesn't create");
- }
- */
- void printMatrix(){
- System.out.println("Adjancecy Matrix");
- System.out.println("----------------");
- for (i = 0; i < adjancecyM.length; ++i) {
- for (j = 0; j < adjancecyM.length; ++j)
- System.out.print(adjancecyM[i][j] + " ");
- System.out.println();
- }
- }
- //minimum and max degrees of a vertex
- for (i = 0; i < adjancecyM.length; i++) {
- degreeVertex = 0;
- for (j = 0; j < adjancecyM.length; j++)
- if (adjancecyM[i][j] == 1) {
- degreeVertex++;
- degreeTotal++;
- }
- if (degreeVertex > degreeMax) degreeMax = i;
- if (degreeVertex < degreeMin) degreeMin = i;
- System.out.println("For vertex: " + i + " degree is " + degreeVertex);
- }
- System.out.println("Max vertex: " + degreeMax + " and Min vertex: " + degreeMin);
- if (degreeTotal == 2 * sum) System.out.println("Equal!");
- else
- System.out.println("Degrees != 2*Edges");
- } else
- System.out.print("u have insert an even number, let's try again!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement