Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. public bool DeleteVertex(char name)
  2. {
  3. int exists = Names.FindIndex(e => e == name);
  4. if (exists != -1)
  5. {
  6. int index = exists;
  7. int n = this.AdjacencyMatrix.GetLength(0);
  8. int[,] NewAdjacencyMatrix = new int[n - 1, n - 1];
  9.  
  10. bool iFlag = false;
  11. for (int i = 0; i < n - 1; i++)
  12. {
  13. if (i >= index)
  14. iFlag = true;
  15.  
  16. bool jFlag = false;
  17. for (int j = 0; j < n - 1; j++)
  18. {
  19. if (j >= index)
  20. jFlag = true;
  21.  
  22. if (iFlag && jFlag)
  23. NewAdjacencyMatrix[i, j] = AdjacencyMatrix[i + 1, j + 1];
  24. else if (iFlag && !jFlag)
  25. NewAdjacencyMatrix[i, j] = AdjacencyMatrix[i + 1, j];
  26. else if (!iFlag && jFlag)
  27. NewAdjacencyMatrix[i, j] = AdjacencyMatrix[i, j + 1];
  28. else
  29. NewAdjacencyMatrix[i, j] = AdjacencyMatrix[i, j];
  30. }
  31. }
  32. AdjacencyMatrix = NewAdjacencyMatrix;
  33. Names.RemoveAt(index);
  34. return true;
  35. }
  36. else
  37. return false;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement