public int Max() { if (stack.Count == 0) { throw new Exception("no element in stack"); } MaxInfo topMax = maxStack.Peek() as MaxInfo; return(topMax.value); }
public int Pop() { if (stack.Count == 0) { throw new Exception("no element to pop"); } int top = Convert.ToInt32(stack.Pop()); MaxInfo topMax = maxStack.Peek() as MaxInfo; if (topMax.value == top) { --topMax.count; if (topMax.count == 0) { maxStack.Pop(); } } return(top); }
public void Push(int value) { if (stack.Count > 0) { MaxInfo topMax = maxStack.Peek() as MaxInfo; if (topMax.value == value) { ++topMax.count; } else if (topMax.value < value) { maxStack.Push(new MaxInfo(value, 1)); } } else { maxStack.Push(new MaxInfo(value, 1)); } stack.Push(value); }
IEnumerator LoadMaxInfo() { var sourceUrl = (MasterController.Instance.ServerManager.ServerBundleRoot + CurrentAssetInfo.Id + "/maxinfo.json").Replace(" ", "%20"); WWW www = new WWW(sourceUrl); yield return(www); if (www.error == null) { Debug.Log("data: " + www.text); CurrentMaxInfo = MaxInfo.CreateFromJSON(www.text); Debug.Log(CurrentMaxInfo.ToString()); InfoTextArea.text = CurrentMaxInfo.ToString(); } else { Debug.LogError("WWW error: " + www.error); } }