private bool IsVailed(string str) { ArryStack <char> arryStack = new ArryStack <char>(); for (int i = 0; i < str.Length; i++) { if (str[i] == '{' || str[i] == '[' || str[i] == '(') { arryStack.Push(str[i]); } else if (str[i] == '}' || str[i] == ']' || str[i] == ')') { if (arryStack.IsEmpty() == true) { return(false); } else if (arryStack.Peek() == '{') { if (str[i] == '}') { arryStack.Pop(); } else { return(false); } } else if (arryStack.Peek() == '[') { if (str[i] == ']') { arryStack.Pop(); } else { return(false); } } else if (arryStack.Peek() == '(') { if (str[i] == ')') { arryStack.Pop(); } else { return(false); } } } } return(arryStack.IsEmpty()); }
private void btn_ArrayStack_Click(object sender, EventArgs e) { ArryStack <int> arryStack = new ArryStack <int>(); for (int i = 0; i < 5; i++) { arryStack.Push(i); Console.WriteLine(arryStack.ToString()); } arryStack.Pop(); Console.WriteLine(arryStack.ToString()); }