Advertisement
mikymaione

Algo 20171016 3

Dec 16th, 2017
367
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.33 KB | None | 0 0
  1. dfs_visita(G, v)
  2.     v.color = Color.Gray
  3.  
  4.     for (x in G.Adj[v])
  5.         if (x.color == Color.White)
  6.             dfs_visita(G, x)
  7.  
  8.     v.color = Color.Black
  9.  
  10.  
  11. Alg_20171016(G, B[])
  12.     // inizializzazione ------------------------------------
  13.     V1 = new List()
  14.     V2 = new List()
  15.     VU = new List()
  16.  
  17.     for (x in G.V)
  18.         x.color = Color.White
  19.         VU.Add(x)
  20.        
  21.     Gt = Trasposto()
  22.     // inizializzazione ------------------------------------
  23.  
  24.     // G ---------------------------------------------------
  25.     for (x in B)
  26.         dfs_visita(G, x)
  27.  
  28.     for (x in B)
  29.         x.color = Color.White
  30.  
  31.     for (x in G.V)
  32.         if (x.color == Color.Black)
  33.             V2.Add(x)
  34.             if (!VU.Remove(x))
  35.                 Console.WriteLine("Gli insiemi non esistono!")
  36.                 return false
  37.  
  38.     for (x in G.V)
  39.         x.color = Color.White
  40.     // G ---------------------------------------------------
  41.  
  42.     // GT --------------------------------------------------
  43.     for (x in B)
  44.         x.color = Color.Black
  45.  
  46.     for (x in B)
  47.         dfs_visita(Gt, x)
  48.  
  49.     for (x in B)
  50.         x.color = Color.White
  51.  
  52.     for (x in Gt.V)
  53.         if (x.color == Color.Black)
  54.             V1.Add(x)
  55.             if (!VU.Remove(x))
  56.                 Console.WriteLine("Gli insiemi non esistono!")
  57.                 return false
  58.     // GT --------------------------------------------------
  59.  
  60.     Console.WriteLine('V1:')
  61.     for (x in V1)
  62.         Console.Write(x)
  63.  
  64.     Console.WriteLine('V2:')
  65.     for (x in V2)
  66.         Console.Write(x)
  67.  
  68.     return true
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement