nie-ii-year

lab stuff from undergrad second year.
git clone http://git.hanabi.in/repos/nie-ii-year.git
Log | Files | Refs | LICENSE

iterative.js (1013B)


      1 function main(){
      2     var isComplete = new Boolean;
      3     var n = getVertices();
      4     var arr = new Array(n);
      5     for(var i = 0; i < n; i++)
      6         arr[i] = new Array(n);
      7     getMatrix(arr);
      8     isComplete = check(arr);
      9     if(isComplete) print("The graph is a complete graph.");
     10     else print("It is not a complete graph");
     11 }
     12 
     13 function getVertices(){
     14     do{
     15         print("Enter number of vertices");
     16         v = parseInt(readline());
     17         if(v < 1 || v % 1 !== 0)
     18             print("Invalid input, try again");
     19     }while(v < 1 || v % 1 !== 0);
     20     return v;
     21 }
     22 
     23 function getMatrix(arr){
     24     for(var row = 0; row < arr.length; row++)
     25         for(var col = 0; col < arr.length; col++)
     26             arr[row][col] = readline();
     27 }
     28             
     29 function check(arr){
     30 //    print(arr);
     31     for(var i = 1; i < arr.length; i++){
     32             if(arr[i][i] != 0) return false;
     33             for(var j = 0; j < i; j++)
     34                 if(arr[i][j] != 1)
     35                     return false;    
     36     }
     37     return true;
     38 }
     39 
     40 main();