nie-ii-year

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

commit c79bdf8b59dde1ae7f6e387841469556a34224d6
parent 807fdf5c0d55f7206c4a7b780ef747d664fc5d71
Author: Agastya Chandrakant <acagastya@outlook.com>
Date:   Wed,  7 Feb 2018 11:51:07 +0530

Create iterative.js
Diffstat:
As4/algorithms/completegraph/iterative.js | 40++++++++++++++++++++++++++++++++++++++++
1 file changed, 40 insertions(+), 0 deletions(-)

diff --git a/s4/algorithms/completegraph/iterative.js b/s4/algorithms/completegraph/iterative.js @@ -0,0 +1,40 @@ +function main(){ + var isComplete = new Boolean; + var n = getVertices(); + var arr = new Array(n); + for(var i = 0; i < n; i++) + arr[i] = new Array(n); + getMatrix(arr); + isComplete = check(arr); + if(isComplete) print("The graph is a complete graph."); + else print("It is not a complete graph"); +} + +function getVertices(){ + do{ + print("Enter number of vertices"); + v = parseInt(readline()); + if(v < 1 || v % 1 !== 0) + print("Invalid input, try again"); + }while(v < 1 || v % 1 !== 0); + return v; +} + +function getMatrix(arr){ + for(var row = 0; row < arr.length; row++) + for(var col = 0; col < arr.length; col++) + arr[row][col] = readline(); +} + +function check(arr){ +// print(arr); + for(var i = 1; i < arr.length; i++){ + if(arr[i][i] != 0) return false; + for(var j = 0; j < i; j++) + if(arr[i][j] != 1) + return false; + } + return true; +} + +main();