void SpawnNext() { if (monsters.IsEmpty() && Monster.numMonsters == 0) { IncrementWave(); } else if (!monsters.IsEmpty()) { string monster = monsters.Pop(); float seconds; if (float.TryParse(monster, out seconds)) { interval = seconds; CancelInvoke(); InvokeRepeating("SpawnNext", 0f, interval); } else { GameObject tmp = Instantiate(monsterPrefab, transform.position, Quaternion.identity); ModifyMonster(monster, tmp); } } }
public void IsEmpty_NormalConditions_Test() { CustomQueue <int> testQueue = new CustomQueue <int>(); var empty = testQueue.IsEmpty(); Assert.That(empty, Is.EqualTo(true)); }
static void Main(string[] args) { using (reader = File.OpenText("input.txt")) using (writer = new StreamWriter(File.Create("output.txt"))) { int n = reader.ReadInt(); if (n == 0) { writer.Write(0); return; } Node <int>[] arr = new Node <int> [n]; for (int i = 0; i < n; i++) { arr[i] = new Node <int>(); } for (int i = 0; i < n; i++) { int key = reader.ReadInt(); int leftIdx = reader.ReadInt(); int rightIdx = reader.ReadInt(); arr[i].Key = key; if (leftIdx != 0) { arr[i].Left = arr[leftIdx - 1]; arr[leftIdx - 1].Parent = arr[i]; } if (rightIdx != 0) { arr[i].Right = arr[rightIdx - 1]; arr[rightIdx - 1].Parent = arr[i]; } } Node <int> root = null; for (int i = 0; i < n && root == null; i++) { if (arr[i].Parent == null) { root = arr[i]; } } CustomQueue <Node <int> > queue = new CustomQueue <Node <int> >(n + 1); queue.Enqueue(root); root.Level = 1; int maxLevel = 1; while (!queue.IsEmpty()) { var node = queue.Dequeue(); if (node.Left != null) { node.Left.Level = node.Level + 1; maxLevel = Math.Max(maxLevel, node.Level + 1); queue.Enqueue(node.Left); } if (node.Right != null) { node.Right.Level = node.Level + 1; maxLevel = Math.Max(maxLevel, node.Level + 1); queue.Enqueue(node.Right); } } writer.Write(maxLevel); } }