Create a temp array to hold visited flag of all elements . Note that , calloc is used here so that all values are initialized as false
let visited = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) { visited [ i ] = false ; } let i ; for ( i = 0 ; i < n ; i ++ ) {