private void TakeNextStep(ref MazeCell Current, int[] next, ref MyStack stack) { // Directions are based off of how NEXT is set during CHECK-AROUND method if (Current.Column > next[0] && Current.Row == next[1]) { // Go West = 1 stack.Push(1); ChangeTile(Current); Current.MoveWest(); } else if (Current.Column == next[0] && Current.Row < next[1]) { // Go South = 2 stack.Push(2); ChangeTile(Current); Current.MoveSouth(); } else if (Current.Column < next[0] && Current.Row == next[1]) { // Go East = 3 stack.Push(3); ChangeTile(Current); Current.MoveEast(); } else if (Current.Column == next[0] && Current.Row > next[1]) { // Go North = 4 stack.Push(4); ChangeTile(Current); Current.MoveNorth(); } else { if (next[0] == -1 || next[1] == -1) { // NO PATH RewindPath(ref stack, ref Current); } else { // Error in Path } } }
static void Main() { string[] text; using (StreamReader sr = new StreamReader("C:/Users/ZooM/Desktop/Документы/WarAndWorld.txt")) { text = sr.ReadToEnd().Split(new[] { ' ', '.', '!', '?', '/', '\"', '\'', '(', ')', ':', ',', ';' }); } var mySt = new MyStack <string>(text.Length); Stopwatch timer = new Stopwatch(); timer.Start(); foreach (var word in text) { mySt.Push(word); } timer.Stop(); Console.WriteLine("Count: {0}", text.Length); Console.WriteLine(); Console.WriteLine("Time push: {0}", timer.ElapsedMilliseconds); //timer.Start(); //foreach (var word in text) //{ // mySt.Contains(word); //} //timer.Stop(); //Console.WriteLine(); //Console.WriteLine("Time contains All Elements: {0}", timer.ElapsedMilliseconds); timer.Start(); foreach (var word in text) { mySt.Pop(); } timer.Stop(); Console.WriteLine(); Console.WriteLine("Time pop All Elements: {0}", timer.ElapsedMilliseconds); Console.ReadKey(); }
public bool Timoshka2(string String) { MyStack <char> M1 = new MyStack <char> (String.Length); bool flag = false; for (int i = 0; i < String.Length; i++) { if ((char)String[i] == 40 || (char)String[i] == 91 || (char)String[i] == 123) { M1.Push((char)String[i]); } if (((char)String[i] == 41) || ((char)String[i] == 93) || (char)String[i] == 125) { if (M1.IsEmpty() != true) { if (M1.Top() == ((char)String[i] - 2) || M1.Top() == ((char)String[i] - 1)) { M1.Pop(); } else { flag = true; break; } } else { flag = true; break; } } } if (flag == false && M1.IsEmpty() == true) { return(true); } else { return(false); } }
static void Main(string[] args) { MyStack <int> myStack = new MyStack <int>(); myStack.Push(1); myStack.Push(2); myStack.Push(3); myStack.Push(4); myStack.Pop(); var stack = myStack.ToArray(); foreach (var item in stack) { Console.WriteLine(item); } Console.WriteLine(myStack.Peek()); Console.ReadLine(); }
static void Main(string[] args) { //create MyStack type string MyStack <string> st = new MyStack <string>(); Console.WriteLine("-----Enter length stack-----: "); st.lengthStack = int.Parse(Console.ReadLine()); while (true) { Console.WriteLine("what do you want with stack? :"); Console.WriteLine("1: push"); Console.WriteLine("2: pop"); Console.WriteLine("3: Current value"); //enter number in 1,2,3 int number = int.Parse(Console.ReadLine()); if (number == 1) { Console.WriteLine("Enter value stack: "); //enter value stack string valueStack = Console.ReadLine(); //add value st.Push(valueStack); } else if (number == 2) { //show value pop try { Console.WriteLine("---You are poped a value out stack--- :" + st.Pop()); } catch { continue; } } else if (number == 3) { //get value current Console.WriteLine("Current value ---> " + st.GetValue()); } } }
static void Main(string[] args) { MyStack myStack = new MyStack(2); try { myStack.Pop(); } catch (MyStackIsEmptyException e) { Console.WriteLine(e.Message); } myStack.Push(0); Console.WriteLine(myStack.Pop()); myStack.Push(1); myStack.Push(2); myStack.Push(3); }
static void Main() { MyStack <int> stack = new MyStack <int>(); stack.Push(3); stack.Push(5); stack.Push(15); stack.Push(23); stack.Push(81); stack.Push(100); var poped = stack.Pop(); Console.WriteLine("Pop element {0}", poped); Console.WriteLine("Peek element {0}", stack.Peek()); foreach (var number in stack) { Console.WriteLine(number); } }
static void Main(string[] args) { MyStack <int> myStack = new MyStack <int>(); for (int i = 0; i < 10; i++) { myStack.Push(i); } Stack <int> stack = new Stack <int>(); for (int i = 0; i < 5; i++) { stack.Push(i); } Console.WriteLine(stack.Peek()); stack.Pop(); stack.Pop(); Console.WriteLine(stack.Peek()); }
private void RewindPath(ref MyStack stack, ref MazeCell Current) { int ThisPop = stack.Pop(); bool revearsing = true; while (revearsing) { // Check For Start if (ThisPop != 0) { // IS NOT START // Check Step if (ThisPop == -1) { // IS CHOICE - Try New Path revearsing = false; // Put Pop back on Stack to signify a choice stack.Push(-1); } else { // IS NOT CHOICE - Keep Popping ThisPop = stack.Pop(); UpdateRewindCell(Current.Column, Current.Row); MoveCurrent(ThisPop, ref Current, ref stack); } } else { // IS START - No Path revearsing = false; stack.Push(0); } } }
static void Main() { Stack <int> st = new Stack <int>(); MyStack <int> mySt = new MyStack <int>(); }
private void CalculatePath(ref List <string> Path) { if (IsMazeValid()) { MyStack pathStack = new MyStack(); // 0 Represents the Starting Point pathStack.Push(0); bool isSearching = true; // TODO: Set From Form MazeCell Current = new MazeCell(); int[] Next = new int[2] { 1, 1 }; while (isSearching) { SetNextStep(Current, ref Next, ref pathStack); TakeNextStep(ref Current, Next, ref pathStack); UpdatePathCell(Current.Column, Current.Row); CheckFinished(ref isSearching, Current); } for (int i = pathStack.Length; i > 0; i--) { switch (pathStack.Pop()) { case -1: // Don't write that a decision was made break; case 0: // Starting Location - Not Technically a Move break; case 1: Path.Add("West"); break; case 2: Path.Add("South"); break; case 3: Path.Add("East"); break; case 4: Path.Add("North"); break; default: Path.Add("Error"); break; } } Path.Reverse(); } else { MessageBox.Show("The Maze isn't valid."); } }
static void Main(string[] args) { MyStack <int> stack = new MyStack <int>(); stack.Pop(); }
double Vichislenie(Queue <string> S, ref char s1) { MyStack <double> M2 = new MyStack <double>(S.Count()); double result = 0; double p1 = 0; double p2 = 0; bool flag = true; while (S.IsEmpty() != true) { if (S.Top() == "+" || S.Top() == "-" || S.Top() == "*" || S.Top() == "/") { if (S.Top() == "+") { S.Pop(); p1 = M2.Top(); M2.Pop(); p2 = M2.Top(); M2.Pop(); M2.Push(p1 + p2); if (S.IsEmpty() == true) { result = M2.Top(); break; } } if (S.Top() == "*") { S.Pop(); p1 = M2.Top(); M2.Pop(); p2 = M2.Top(); M2.Pop(); M2.Push(p1 * p2); if (S.IsEmpty() == true) { result = M2.Top(); break; } } if (S.Top() == "-") { S.Pop(); p1 = M2.Top(); M2.Pop(); p2 = M2.Top(); M2.Pop(); M2.Push(p2 - p1); if (S.IsEmpty() == true) { result = M2.Top(); break; } } if (S.Top() == "/") { S.Pop(); p1 = M2.Top(); M2.Pop(); p2 = M2.Top(); M2.Pop(); if (p1 != 0) { M2.Push(p2 / p1); } else { s1 = '~'; flag = false; break; } if (S.IsEmpty() == true) { result = M2.Top(); break; } } } else { M2.Push(Convert.ToInt64(S.Pop())); } } if (flag != false) { return(result); } else { return(0); } }