public void AddNode(string city) { Size++; var temp = new GraphTableNode[Size]; Array.Copy(_cities, temp, _cities.Length); _cities = temp; _cities[Size - 1] = new GraphTableNode { City = city, Links = new int[Size] }; }
public void DelNode(int from) { if (Size == 0) { throw new ArgumentNullException(); } foreach (var t in _cities) { t.Links[@from - 1] = 0; } var temp = new GraphTableNode[Size - 1]; for (var i = 0; i < temp.Length; i++) { if (i >= from - 1) { temp[i] = _cities[i + 1]; for (var j = 0; j < Size - 1; j++) { if (j >= from - 1) { temp[i].Links[j] = _cities[i].Links[j + 1]; } else { temp[i].Links[j] = _cities[i].Links[j]; } } } else { temp[i] = _cities[i]; for (var j = 0; j < Size - 1; j++) { if (j >= from - 1) { temp[i].Links[j] = _cities[i].Links[j + 1]; } else { temp[i].Links[j] = _cities[i].Links[j]; } } } } Size--; }
public GraphTableNode[] ToArray() { if (Size == 0) { throw new ArgumentNullException(); } var temp = new GraphTableNode[Size]; bool[] visited = new bool[Size]; Queue <GraphTableNode> turn = new Queue <GraphTableNode>(); turn.Enqueue(_cities[0]); visited[0] = true; var index = 0; while (turn.Count != 0) { var item = turn.Dequeue(); temp[index] = item; index++; for (var i = 0; i < Size; i++) { for (var j = 0; j < Size; j++) { if (visited[i]) { continue; } visited[i] = true; turn.Enqueue(_cities[i]); } } } return(temp); }
public GraphTableNode[] ToArray() { if (Size == 0) { throw new ArgumentNullException(); } var temp = new GraphTableNode[Size]; bool[] visited = new bool[Size]; Queue<GraphTableNode> turn = new Queue<GraphTableNode>(); turn.Enqueue(_cities[0]); visited[0] = true; var index = 0; while (turn.Count != 0) { var item = turn.Dequeue(); temp[index] = item; index++; for (var i = 0; i < Size; i++) { for (var j = 0; j < Size; j++) { if (visited[i]) continue; visited[i] = true; turn.Enqueue(_cities[i]); } } } return temp; }
public void Init(GraphTableNode[] array) { if (array == null) { throw new NullReferenceException(); } _cities = array; Size = array.Length; }