当前位置: 首页>>代码示例>>C#>>正文


C# Stack.ElementAt方法代码示例

本文整理汇总了C#中Stack.ElementAt方法的典型用法代码示例。如果您正苦于以下问题:C# Stack.ElementAt方法的具体用法?C# Stack.ElementAt怎么用?C# Stack.ElementAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Stack的用法示例。


在下文中一共展示了Stack.ElementAt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ElementAt

        public void ElementAt()
        {
            var stack = new Stack();

            stack.Push(Integer256.Zero);
            stack.Push(Integer256.One);
            stack.Push(Integer256.Two);
            stack.Push(Integer256.Three);

            Assert.AreEqual(Integer256.Zero, stack.ElementAt(3));
            Assert.AreEqual(Integer256.One, stack.ElementAt(2));
            Assert.AreEqual(Integer256.Two, stack.ElementAt(1));
            Assert.AreEqual(Integer256.Three, stack.ElementAt(0));
        }
开发者ID:ajlopez,项目名称:EthSharpVm,代码行数:14,代码来源:StackTests.cs

示例2: Build

        /// <summary>
        /// Строит выпуклую оболочку по точкам.
        /// </summary>
        /// <param name="aXPoints">Координаты X.</param>
        /// <param name="aYPoints">Координаты Y.</param>
        /// <param name="aSideValue">Направление выпуклой оболочки (-1 или 1).</param>
        /// <returns>индексы седловых точек.</returns>
        public static int[] Build(double[] aXPoints, double[] aYPoints, int aSideValue)
        {
            CheckRegulations(aXPoints, aYPoints, aSideValue);

            var saddlePoints = new Stack<int>();
            var preLastPoint = 0;
            var lastPoint = 1;
            saddlePoints.Push(preLastPoint);
            saddlePoints.Push(lastPoint);

            var pointsCount = aXPoints.Length;
            for (var i = 2; i < pointsCount; ++i) {
                while (lastPoint != 0 &&
                       !IsSameDirection(aXPoints[preLastPoint],
                                        aYPoints[preLastPoint],
                                        aXPoints[i],
                                        aYPoints[i],
                                        aXPoints[lastPoint],
                                        aYPoints[lastPoint],
                                        aSideValue)) {
                    lastPoint = preLastPoint;
                    saddlePoints.Pop();
                    if (preLastPoint == 0) {
                        preLastPoint = -1;
                    }
                    else {
                        preLastPoint = saddlePoints.ElementAt(1);
                    }
                }

                preLastPoint = lastPoint;
                lastPoint = i;
                saddlePoints.Push(i);
            }

            return saddlePoints.Reverse().ToArray();
        }
开发者ID:desla,项目名称:SlabGeometryControl,代码行数:44,代码来源:ConvexHull.cs

示例3: Add

 // Add multiple game pieces to the stack at this position.
 public void Add(Stack<TzaarPiece> somePieces)
 {
     for (int i = somePieces.Count - 1; i >= 0; i--)
         this.pieces.Push(somePieces.ElementAt(i));
 }
开发者ID:jiweaver,项目名称:daedalus-game-manager,代码行数:6,代码来源:TzaarBoardPosition.cs

示例4: button1_Click

        private void button1_Click(object sender, EventArgs e)
        {
            if(!checkend)
            {
            card p1_drawcard,p2_drawcard;

            p1_drawcard = p1_deck.drawcard();
            p2_drawcard = p2_deck.drawcard();

            P1_txt.Text = p1_drawcard.getname();
            P2_txt.Text = p2_drawcard.getname();

            if (p1_drawcard.getval() != p2_drawcard.getval())
            {
                p1_drawagain.Text = "";
                p2_drawagain.Text = "";

                if (p1_drawcard.getval() > p2_drawcard.getval())
                {
                    p1_deck.pushcard(p1_drawcard);
                    p1_deck.pushcard(p2_drawcard);
                    maintxt.Text = "P1 Win this Match";

                }
                else
                {
                    p2_deck.pushcard(p1_drawcard);
                    p2_deck.pushcard(p2_drawcard);
                    maintxt.Text = "P2 Win this Match";

                }
            }
            else
            {
                int sameval = p1_drawcard.getval();
                if(sameval == 14)
                { sameval = 1; }

                p1_drawagain.Text = "P1 Draw Again";
                p2_drawagain.Text = "P2 Draw Again";

                Stack<card> p1_card_again = new Stack<card>(0);
                Stack<card> p2_card_again = new Stack<card>(0);

                if(p1_deck.getnumcard()<sameval)
                {
                    for (int i = 0; i < p1_deck.getnumcard(); i++)
                    {
                        p1_card_again.Push(p1_deck.drawcard());
                        p1_drawagain.Text += " "+p1_card_again.ElementAt(0).getname();
                    }
                }
                else
                {
                    for (int i = 0; i < sameval; i++)
                    {
                        p1_card_again.Push(p1_deck.drawcard());
                        p1_drawagain.Text += " " + p1_card_again.ElementAt(0).getname();
                    }
                }

                if (p2_deck.getnumcard() < sameval)
                {
                    for (int i = 0; i < p2_deck.getnumcard(); i++)
                    {
                        p2_card_again.Push(p2_deck.drawcard());
                        p2_drawagain.Text += " " + p2_card_again.ElementAt(0).getname();
                    }
                }
                else
                {
                    for (int i = 0; i < sameval; i++)
                    {
                        p2_card_again.Push(p2_deck.drawcard());
                        p2_drawagain.Text += " " + p2_card_again.ElementAt(0).getname();
                    }
                }

                if (p1_card_again.ElementAt(p1_card_again.Count-1).getval() > p2_card_again.ElementAt(p2_card_again.Count - 1).getval())
                {
                    int p1_again_size = p1_card_again.Count;
                    int p2_again_size = p2_card_again.Count;

                    for (int i = 0; i < p1_again_size; i++)
                    {
                        p1_deck.pushcard(p1_card_again.Pop());
                    }

                    for (int i = 0; i < p2_again_size; i++)
                    {
                        p1_deck.pushcard(p2_card_again.Pop());
                    }

                    p1_deck.pushcard(p1_drawcard);
                    p1_deck.pushcard(p2_drawcard);
                    maintxt.Text = "P1 Win this Match";

                }
                else if (p1_card_again.ElementAt(p1_card_again.Count - 1).getval() < p2_card_again.ElementAt(p2_card_again.Count - 1).getval())
                {
//.........这里部分代码省略.........
开发者ID:cpe200-158-sec1-0549,项目名称:OOP_week9,代码行数:101,代码来源:Form1.cs

示例5: AIfindWay


//.........这里部分代码省略.........
                        map[top.X + x, top.Y] = false;
                        continue;
                    }

                    if (map[top.X, top.Y + y])
                    {
                        way.Push(new Point(top.X, top.Y + y));
                        map[top.X, top.Y + y] = false;
                        continue;
                    }

                    way.Pop();
                }
                else
                {
                    if (map[top.X, top.Y + y])
                    {
                        way.Push(new Point(top.X, top.Y + y));
                        map[top.X, top.Y + y] = false;
                        continue;
                    }
                    if (map[top.X + x, top.Y])
                    {
                        way.Push(new Point(top.X + x, top.Y));
                        map[top.X + x, top.Y] = false;
                        continue;
                    }

                    x *= -1;
                    y *= -1;

                    if (map[top.X, top.Y + y])
                    {
                        way.Push(new Point(top.X, top.Y + y));
                        map[top.X, top.Y + y] = false;
                        continue;
                    }
                    if (map[top.X + x, top.Y])
                    {
                        way.Push(new Point(top.X + x, top.Y));
                        map[top.X + x, top.Y] = false;
                        continue;
                    }

                    way.Pop();
                }
            }//end for

            if (found && !food_eaten)
            {

                Point next = way.ElementAt<Point>(way.Count - 2);

                int x = next.X - AIHead.X;
                int y = next.Y - AIHead.Y;

                if (x == 0)
                {
                    if (y > 0)
                    {
                        AI.turn(Direction.Down);
                    }
                    else
                    {
                        AI.turn(Direction.Up);
                    }
                }
                else if (y == 0)
                {
                    if (x > 0)
                    {
                        AI.turn(Direction.Right);
                    }
                    else
                    {
                        AI.turn(Direction.Left);
                    }
                }
            }
            else
            {
                //实际上这里是最初版本的AI移动代码
                if (contains[AIHead.X - 1, AIHead.Y] == Contain.empty || contains[AIHead.X - 1, AIHead.Y] == Contain.food)
                {
                    AI.turn(Direction.Left);
                }
                else if (contains[AIHead.X + 1, AIHead.Y] == Contain.empty || contains[AIHead.X + 1, AIHead.Y] == Contain.food)
                {
                    AI.turn(Direction.Right);
                }
                else if (contains[AIHead.X, AIHead.Y - 1] == Contain.empty || contains[AIHead.X - 1, AIHead.Y - 1] == Contain.food)
                {
                    AI.turn(Direction.Up);
                }
                else if (contains[AIHead.X, AIHead.Y + 1] == Contain.empty || contains[AIHead.X - 1, AIHead.Y + 1] == Contain.food)
                {
                    AI.turn(Direction.Down);
                }
            }
        }
开发者ID:hornfezonter,项目名称:Snake_WP7,代码行数:101,代码来源:Scene.cs

示例6: SplitIntoSurfaces

        public List<TopoModel> SplitIntoSurfaces()
        {
            CountShells();
            foreach (TopoTriangle tri in triangles)
                tri.algHelper = tri.shell;

            List<TopoModel> models = new List<TopoModel>();
            Dictionary<int, TopoModel> modelMap = new Dictionary<int, TopoModel>();
            foreach (TopoTriangle tri in triangles)
            {
                int shell = tri.algHelper;
                if (modelMap.ContainsKey(shell))
                {
                    RHVector3 v1 = tri.vertices[0].pos;
                    RHVector3 v2 = tri.vertices[1].pos;
                    RHVector3 v3 = tri.vertices[2].pos;
                    RHVector3 n = tri.normal;
                    modelMap[shell].addTriangle(v1.x, v1.y, v1.z, v2.x, v2.y, v2.z, v3.x, v3.y, v3.z, n.x, n.y, n.z);
                }
                else
                {
                    List<TopoTriangleDistance> intersections = new List<TopoTriangleDistance>();
                    RHVector3 lineStart = tri.Center;
                    RHVector3 lineDirection = tri.normal;
                    double delta;
                    foreach (TopoTriangle test in triangles)
                    {
                        if(test.IntersectsLine(lineStart, lineDirection, out delta))
                        {
                            intersections.Add(new TopoTriangleDistance(delta,test));
                        }
                    }
                    intersections.Sort();
                    Stack<TopoTriangleDistance> tdStack = new Stack<TopoTriangleDistance>();
                    foreach (TopoTriangleDistance td in intersections)
                    {
                        if (td.triangle == tri)
                        {
                            TopoModel m = null;
                            if ((tdStack.Count & 2) == 0)
                            {
                                m = new TopoModel();
                                models.Add(m);
                                modelMap.Add(shell, m);
                            }
                            else
                            {
                                int trueShell = tdStack.ElementAt(tdStack.Count-1).triangle.algHelper;
                                foreach (TopoTriangle t in triangles)
                                {
                                    if (t.algHelper == shell)
                                        t.algHelper = trueShell;
                                }
                                if (modelMap.ContainsKey(trueShell))
                                    m = modelMap[trueShell];
                                else
                                {
                                    m = new TopoModel();
                                    models.Add(m);
                                    modelMap.Add(shell, m);
                                }
                            }
                            RHVector3 v1 = tri.vertices[0].pos;
                            RHVector3 v2 = tri.vertices[1].pos;
                            RHVector3 v3 = tri.vertices[2].pos;
                            RHVector3 n = tri.normal;
                            m.addTriangle(v1.x, v1.y, v1.z, v2.x, v2.y, v2.z, v3.x, v3.y, v3.z, n.x, n.y, n.z);
                            break;
                        }
                        else if (tdStack.Count > 0 && tdStack.Peek().triangle.algHelper == td.triangle.algHelper)
                        {
                            tdStack.Pop();
                        }
                        else
                        {
                            tdStack.Push(td);
                        }
                    }
                }
            }
            foreach (TopoModel m in models)
            {
                m.Analyse();
            }
            return models;
        }
开发者ID:sean-cc,项目名称:Repetier-Host,代码行数:86,代码来源:TopoModel.cs

示例7: ValidRedoStatesAfterMultilevelUndo

        public void ValidRedoStatesAfterMultilevelUndo()
        {
            var correctRedoStates = new Stack<SensorState>();
            correctRedoStates.Push(new SensorState(_undoSensor, new DateTime(2011, 8, 12),
                                                       new Dictionary<DateTime, float> { { new DateTime(2011, 8, 12), 66.77f } }, null));
            correctRedoStates.Push(new SensorState(_undoSensor, new DateTime(2011, 8, 11),
                                            new Dictionary<DateTime, float> { { new DateTime(2011, 8, 12), 66.77f } }, null));

            _undoSensor.Undo(); // At least 1 item must be on undo stack (current state)

            Assert.AreEqual(correctRedoStates.ElementAt(1), _undoSensor.RedoStates[0]);
        }
开发者ID:rwlamont,项目名称:AllItUp,代码行数:12,代码来源:SensorTest.cs

示例8: GetStackValue

 public string GetStackValue(Stack<char> s)
 {
     string tmp = "";
     for (int i = s.Count - 1; i >= 0; --i)
     {
         tmp += s.ElementAt(i);
     }
     return tmp;
 }
开发者ID:jindongwang,项目名称:SyntaxAnalysis,代码行数:9,代码来源:Form1.cs

示例9: Trans2Syn

 private string Trans2Syn(string s)
 {
     JudgeChar jc = new JudgeChar();
     Stack<char> ts = new Stack<char> { };
     for (int i = 0; i < s.Length; ++i)
     {
         if (jc.isDigit(s[i]))
         {
             if (ts.Count == 0 || ts.Peek() != 'i')
             {
                 ts.Push('i');
             }
         }
         else
         {
             ts.Push(s[i]);
         }
     }
     string tmp = "";
     for (int i = ts.Count - 1; i >= 0;--i )
     {
         tmp += ts.ElementAt(i);
     }
     return tmp;
 }
开发者ID:jindongwang,项目名称:SyntaxAnalysis,代码行数:25,代码来源:Form1.cs

示例10: GetStackString

 private string GetStackString(Stack<int> stack)
 {
     int result = 0;
     for (int i = 0; i < stack.Count; i++)
     {
         result += (int)(Math.Pow(10, i) * stack.ElementAt(i));
     }
     return result.ToString();
 }
开发者ID:kjiwu,项目名称:GuessNumberRemaster,代码行数:9,代码来源:Game.cs

示例11: CanStackRule

 public bool CanStackRule(Stack<char> s)
 {
     if (s.Count >= 3)
     {
         int k = 0;
         string tmp = "";
         for (int i = 0; k < 3; ++i,++k)
         {
             tmp += s.ElementAt(i);
         }
         if (word.Contains(tmp))
         {
             return true;
         }
     }
     return false;
 }
开发者ID:jindongwang,项目名称:SyntaxAnalysis,代码行数:17,代码来源:Form1.cs

示例12: StackContent

 private string StackContent(Stack<int> stack)
 {
     string res = string.Empty;
     for (int i = stack.Count - 1; i >= 0; i--)
     {
         res += stack.ElementAt(i); ;
     }
     return res;
 }
开发者ID:raysofice,项目名称:SyntacticAnalyzer,代码行数:9,代码来源:Analysis.cs

示例13: reconocer

        public static void reconocer(String cadena, Clases.Automata automata)
    {
        Stack<Clases.Estado> estadoactual = new Stack<Clases.Estado>();
        
        for (int i = 0; i < automata.listEstados.Count; i++)
        {
            if (automata.listEstados.ElementAt(i).nombre.Equals(automata.inicial))
            {
                estadoactual.Push(automata.listEstados.ElementAt(i));
                for (int j = 0; j < cadena.Length; j++)
                {
                    for (int k = 0; k < estadoactual.Peek().listTransiciones.Count; k++)
                    {
                       // System.out.println(String.valueOf(cadena.charAt(j)));
                        if (cadena.Substring(j,1).Equals(estadoactual.Peek().listTransiciones.ElementAt(k).simbolo))
                        {
                            for (int l = 0; l < automata.listEstados.Count; l++)
                            {
                                if(automata.listEstados.ElementAt(l).nombre.Equals(estadoactual.Peek().listTransiciones.ElementAt(k).destino))
                                {
                                    estadoactual.Push(automata.listEstados.ElementAt(l));
                                    break;
                                }
                            }
                            
                        }
                    }
                }

            }
        }

        if (estadoactual.Peek().aceptador)
        {
            
            Console.WriteLine(cadena + "Es aceptada");
            
        }
        else 
        {
            Console.WriteLine(cadena + "NO Es aceptada");
        }
        for (int i = estadoactual.Count-1; i >= 0; i--) {

            Console.WriteLine(estadoactual.ElementAt(i).nombre);

        }
     
    }
开发者ID:zevaxt,项目名称:Automatas-0.1,代码行数:49,代码来源:Inicial.cs

示例14: Simplify


//.........这里部分代码省略.........
            /*
             * Clearing stack before use it;
             */
            try
            {
                _pbStack.clearStack();
                if (floatAnswer || _outputQueue.Any(v => v.Operator == "/"))
                {
                    //var dblStack = new Stack<double>();

                    // Type{integer,float,operator, memory},{value/mem index}
                    var newStack = new Stack<StackData>();
                    String leftOperand, rightOperand;
                    int leftOperandInt, rightOperandInt;
                    foreach (var nc in _outputQueue)
                    {
                        if (nc.NumberType == NumberClass.NumberTypes.Integer)
                        {
                            newStack.Push(new StackData("int", nc.IntNumber));
                            continue;
                        }

                        if (nc.NumberType == NumberClass.NumberTypes.Float)
                        {
                            newStack.Push(new StackData("float", nc.FloatNumber));
                            continue;
                        }

                        if (nc.NumberType == NumberClass.NumberTypes.Operator)
                        {

                            // Stack filling
                            // if left operand aren't memory cell and right aren't memory cell
                            if ((newStack.Peek().dataType != "mem") && (newStack.ElementAt(1).dataType != "mem"))
                            {
                                rightOperand = newStack.Pop().dataValue.ToString();
                                leftOperand = newStack.Pop().dataValue.ToString();

                                _pbStack.PushCommand(nc.Operator, leftOperand, rightOperand);
                            }
                            else
                            {
                                // if left operand stored in memory
                                if (newStack.Peek().dataType == "mem")
                                {
                                    if (newStack.ElementAt(1).dataType != "mem")
                                    {
                                        leftOperandInt = (int)newStack.Pop().dataValue;
                                        rightOperand = newStack.Pop().dataValue.ToString();

                                        // use push with memory index for left operand
                                        _pbStack.PushCommand(nc.Operator, leftOperandInt, rightOperand);
                                    }
                                    else
                                    {
                                        leftOperandInt = (int)newStack.Pop().dataValue;
                                        rightOperandInt = (int)newStack.Pop().dataValue;
                                        // use push with memory index for left operand
                                        // TODO: Implement Push Command for KOP MEM MEM
                                        _pbStack.PushCommand(nc.Operator, leftOperandInt, rightOperandInt);
                                    }
                                }
                                else
                                {
                                    /* If right operand stored in memory */
                                    // Get left operand value
开发者ID:HBArck,项目名称:CPU-Emulation_PostBinarry,代码行数:67,代码来源:Parser.cs

示例15: InterpretStackTypes

    public void InterpretStackTypes(IDictionary<int, ILOpCode> aOpCodes, Stack<Type> aStack, ref bool aSituationChanged, int aMaxRecursionDepth)
    {
      if (Processed)
      {
        ILInterpretationDebugLine(() => String.Format("{0} skipped for reinterpretation", this));
        return;
      }
      Processed = true;
      ILInterpretationDebugLine(() =>
                                {
                                  var sb = new StringBuilder();
                                  sb.AppendFormat("Interpreting {0}. StackCount = {1}. Contents: ", this, aStack.Count);
                                  foreach (var item in aStack)
                                  {
                                    if (item == null)
                                    {
                                      sb.Append("**NULL**, ");
                                    }
                                    else
                                    {
                                      sb.AppendFormat("{0}, ", item.FullName);
                                    }
                                  }
                                  return sb.ToString().Trim(',', ' ');
                                });
      if (aMaxRecursionDepth == 0)
      {
        throw new Exception("Safety Error: MaxRecursionDepth reached!");
      }

      if (StackOffsetBeforeExecution == null)
      {
        StackOffsetBeforeExecution = 0;
        foreach (var item in aStack)
        {
          if (item == null)
          {
            StackOffsetBeforeExecution = null;
            break;
          }
          StackOffsetBeforeExecution += ILOp.Align(ILOp.SizeOfType(item), 4);
        }
      }

      // if current instruction is the first instruction of a catch statement, "push" the exception type now
      if (CurrentExceptionHandler != null &&
          CurrentExceptionHandler.HandlerOffset == Position)
      {
        if (CurrentExceptionHandler.Flags != SR.ExceptionHandlingClauseOptions.Finally)
        {
          aStack.Push(CurrentExceptionHandler.CatchType);
        }
      }

      if (StackPopTypes.Length > aStack.Count)
      {
        throw new Exception(String.Format("OpCode {0} tries to pop more stuff from analytical stack than there is!", this));
      }

      for (int i = 0; i < StackPopTypes.Length; i++)
      {
        var xActualStackItem = aStack.ElementAt(i);
        if (xActualStackItem == null)
        {
          continue;
        }
        if (StackPopTypes[i] == null)
        {
          StackPopTypes[i] = xActualStackItem;
          aSituationChanged = true;
        }
        if (StackPopTypes[i] != xActualStackItem
          && !StackPopTypes[i].IsAssignableFrom(xActualStackItem)
          && !((StackPopTypes[i].IsPointer || StackPopTypes[i].IsByRef) && (xActualStackItem.IsPointer || xActualStackItem.IsByRef)))
        {
          throw new Exception(String.Format("OpCode {0} tries to pop item at stack position {1} with type {2}, but actual type is {3}",
            this, i, StackPopTypes[i], xActualStackItem));
        }
      }

      foreach (var xPopItem in StackPopTypes)
      {
        aStack.Pop();
      }
      try
      {
        DoInterpretStackTypes(ref aSituationChanged);
      }
      catch (Exception E)
      {
        throw new Exception("Error interpreting stacktypes for " + this, E);
      }
      foreach (var xPushItem in StackPushTypes)
      {
        aStack.Push(xPushItem);
      }
      DoInterpretNextInstructionStackTypes(aOpCodes, aStack, ref aSituationChanged, aMaxRecursionDepth);
    }
开发者ID:iSalva,项目名称:Cosmos,代码行数:98,代码来源:ILOpCode.cs


注:本文中的Stack.ElementAt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。