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


C# Stack.CopyTo方法代码示例

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


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

示例1: TunnelSearch

    private float W; // The width of the tunnel

    #endregion Fields

    #region Constructors

    // Creation function
    public TunnelSearch(Stack<DefaultAction> plan, float width)
    {
        plan.CopyTo(currentPlan,0);

        W = width;
        SqrW = W*W;

        ExtractTunnelZone();
    }
开发者ID:SymphonyX,项目名称:VAST,代码行数:16,代码来源:TunnelSearch.cs

示例2: GridTunnelSearch

    // Creation function
    //public GridTunnelSearch(Stack<DefaultAction> plan, float startTime, float idealGoalTime, GridTimeDomain gtd, int MaxNumberOfNodes, float MaxTime, float T_x, float T_z, float T_t)
    public GridTunnelSearch(Stack<DefaultAction> plan, Vector3 startPos, float startTime, float idealGoalTime, GridTimeDomain gtd, int MaxNumberOfNodes, float MaxTime, float T_d, float T_t, float startSpeed = 0)
    {
        currentPlan = new DefaultAction[plan.Count];
        plan.CopyTo(currentPlan,0);

        this.T_d = T_d;
        //this.T_x = T_x;
        //this.T_z = T_z;
        this.T_t = T_t;

        this.maxTime = MaxTime;

        int startIndex = 0;
        //GridPlanningState startPlanningState = currentPlan[startIndex].state as GridPlanningState;
        //while (startPlanningState == null)
        //{
        //	startIndex++;
        //	startPlanningState = currentPlan[startIndex].state as GridPlanningState;
        //}

        //startState = new GridTimeState(startPlanningState.currentPosition, startTime, startSpeed);
        startState = new GridTimeState(startPos, startTime, startSpeed);
        lastState = new GridTimeState((currentPlan[currentPlan.Length-1].state as GridPlanningState).currentPosition, idealGoalTime);

        gridTimeDomain = gtd;

        float dist = (startState.currentPosition - lastState.currentPosition).magnitude;
        // TODO: what to do if there is no time???
        float minSpeed = dist / (idealGoalTime-startTime);
        if (minSpeed < 0)
            minSpeed = GridTimeDomain.MIN_SPEED;

        //tunnel = ConvertPlan(gtd.minSpeed, gtd.midSpeed, gtd.maxSpeed);
        tunnel = ConvertPlan(startTime, minSpeed, GridTimeDomain.MID_SPEED, GridTimeDomain.MAX_SPEED);

        //for(int aux = 0; aux < tunnel.tunnelMinVelocity.Length; aux++)
        //	Debug.Log("Tunnel "+aux+":"+tunnel.tunnelMinVelocity[aux]);

         	tunnelPlanner = new BestFirstSearchPlanner();

        List<PlanningDomainBase> domainList = new List<PlanningDomainBase>();
        domainList.Add(gridTimeDomain);

        tunnelPlanner.init(ref domainList, MaxNumberOfNodes);

        // MUBBASIR TESTING ARA STAR PLANNER HERE
        araStarPlanner = new ARAstarPlanner ();
        araStarPlanner.init(ref domainList, MaxNumberOfNodes);

        goalReached = false;

        ComputeTunnelSearch();

        //ComputeTunnelSearchStatePlan ();
    }
开发者ID:SymphonyX,项目名称:VAST,代码行数:57,代码来源:GridTunnelSearch.cs

示例3: Start

    // Use this for initialization
    void Start()
    {
        GameObject[] gos = GameObject.FindObjectsOfType( typeof( GameObject ) ) as GameObject[];
        #region Dictionary
        MyDictionary = new Dictionary<string,int>();
        MyDictionary.Add("Zombies",10);
        //prints 10;
        Debug.Log ( MyDictionary["Zombies"] );

        //int and object
        Dictionary<int, Object> obs = new Dictionary<int, Object>();
        Object[] allObjects = GameObject.FindObjectsOfType( typeof( Object ) ) as Object[];

        for( int i = 0; i < allObjects.Length; i++ ) {
            obs.Add( i, allObjects[i] );
            Debug.Log( obs[i] );
        }

        //lists GameObject names in the scene
        Dictionary<string, int> SceneDictionary = new Dictionary<string, int>();
        foreach( GameObject go in gos )
        {

            bool containsKey = SceneDictionary.ContainsKey(go.name);
            if( containsKey )
            {
                SceneDictionary[go.name] += 1;
            }
            else
            {
                SceneDictionary.Add(go.name, 1);
            }
        }
        objectNames = new string[SceneDictionary.Keys.Count];
        objectCounts = new int[SceneDictionary.Values.Count];
        SceneDictionary.Keys.CopyTo(objectNames, 0);
        SceneDictionary.Values.CopyTo(objectCounts, 0);
        SceneDictionary.Remove("Main Camera");
        #endregion

        #region Stack
        //create a new stack
        Stack objectStack = new Stack();
        //assign objects to the stack using push
        foreach( GameObject go in gos )
        {
            objectStack.Push( go );
        }
        //initialize the class scope ObjectStack to view in the inspector panel
        ObjectStack = new GameObject[objectStack.Count];
        //copy the stack to the array in Unity
        objectStack.CopyTo(ObjectStack, 0 );
        #endregion
    }
开发者ID:kurtzhang,项目名称:UnityProjects,代码行数:55,代码来源:Dictionaries.cs

示例4: PosTest1

    public bool PosTest1()
    {
        bool retVal = true;

        const string c_TEST_ID = "P001";
        string c_TEST_DESC = "PosTest1: copy data from non-empty stack to array.";
        string errorDesc;

        int[] operands = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
        Stack<int> operandStack = new Stack<int>((IEnumerable<int>)operands);
        int[] expectedValues = new int[] { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 };
        int[] actualValues;
        int startIndex, length;
        length = operands.Length + 
            TestLibrary.Generator.GetInt32() % (c_MAX_ARRAY_LENGTH - operands.Length + 1);
        actualValues = new int[length];

        if(actualValues.Length == operands.Length) {
            startIndex = 0;
        }
        else {	
            startIndex = TestLibrary.Generator.GetInt32() % (actualValues.Length - operands.Length);
        }

        TestLibrary.TestFramework.BeginScenario(c_TEST_DESC);
        try
        {
            operandStack.CopyTo(actualValues, startIndex);
            if (!this.VerifyCopyToResult(actualValues, startIndex, expectedValues))
            {
                errorDesc = "Failed to copy data from stack to array." +
                    "\nThe stack is " + this.GetArrayData(expectedValues) +
                    "\nThe start index is " + startIndex + ", and actual array elements is " +
                    this.GetArrayData(actualValues, startIndex, expectedValues.Length);
                TestLibrary.TestFramework.LogError("001" + " TestId-" + c_TEST_ID, errorDesc);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            errorDesc = "Unexpected exception: " + e +
                "\nThe stack is " + this.GetArrayData(expectedValues) + 
                "\nThe start index is " + startIndex + ".";
            TestLibrary.TestFramework.LogError("002" + " TestId-" + c_TEST_ID, errorDesc);
            retVal = false;
        }

        return retVal;
    }
开发者ID:l1183479157,项目名称:coreclr,代码行数:49,代码来源:stackcopyto.cs

示例5: CircuitDefinition

 internal CircuitDefinition(int start, Stack<int> circuit,
     IGraphNode[] participatingNodes)
 {
     int[] stackedContent = new int[circuit.Count];
     circuit.CopyTo(stackedContent, 0);
     _circuit = new IGraphNode[stackedContent.Length];
     for (int index = stackedContent.Length - 1, circuitIndex = 0;
         0 <= index;
         index--, circuitIndex++)
     {
         _circuit[circuitIndex] = participatingNodes[stackedContent[index]];
     }
     Start = start;
     return;
 }
开发者ID:BlueSkeye,项目名称:ApkRe,代码行数:15,代码来源:CircuitDefinition.cs

示例6: PosTest2

    public bool PosTest2()
    {
        bool retVal = true;

        const string c_TEST_ID = "P002";
        string c_TEST_DESC = "PosTest2: copy data from empty stack to array.";
        string errorDesc;

        Stack<int> operandStack = new Stack<int>();
        int[] actualValues;
        int startIndex, length;
        length = (TestLibrary.Generator.GetInt32() % (c_MAX_ARRAY_LENGTH))+1;
        actualValues = new int[length];
        int expectedValue = -1;

        startIndex = TestLibrary.Generator.GetInt32() % actualValues.Length;	
        actualValues[startIndex] = expectedValue;

        TestLibrary.TestFramework.BeginScenario(c_TEST_DESC);
        try
        {
            operandStack.CopyTo(actualValues, startIndex);
            if (actualValues[startIndex] != expectedValue)
            {
                errorDesc = "Failed to copy data from empty stack to array." + 
                    "\nThe start index is " + startIndex + "and values at this postion is " +
                    actualValues[startIndex] + ".";
                TestLibrary.TestFramework.LogError("003" + " TestId-" + c_TEST_ID, errorDesc);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            errorDesc = "Unexpected exception: " + e + 
                "\nThe stack is empty." +
                "\nThe start index is " + startIndex + "and values at this postion is " + 
                actualValues[startIndex] + ".";
            TestLibrary.TestFramework.LogError("004" + " TestId-" + c_TEST_ID, errorDesc);
            retVal = false;
        }

        return retVal;
    }
开发者ID:l1183479157,项目名称:coreclr,代码行数:43,代码来源:stackcopyto.cs

示例7: Stack

        private static void Stack()
        {
            // Stack
            Stack<int> stack = new Stack<int>();
            // add
            stack.Push(5);
            // peek
            int peek =stack.Peek();

            // remove last
            int last =stack.Pop();
            // count
            int count = stack.Count;
            // find
            bool exist = stack.Contains(5);

            // copy to array
            int[] copy= new int[100];
            stack.CopyTo(copy,0);

            // convert it to array
            copy = stack.ToArray();
        }
开发者ID:cleancodenz,项目名称:LEDA,代码行数:23,代码来源:Program.cs

示例8: NegTest4

    public bool NegTest4()
    {
        bool retVal = true;

        const string c_TEST_ID = "N004";
        string c_TEST_DESC = "NegTest4: arrayIndex is equal to or greater than the length of array.";
        string errorDesc;

        int[] operands = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
        Stack<int> operandStack = new Stack<int>((IEnumerable<int>)operands);
        int length = operands.Length +
            TestLibrary.Generator.GetInt32() % (c_MAX_ARRAY_LENGTH - operands.Length + 1);
        int[] values = new int[length];
        int startIndex = values.Length + TestLibrary.Generator.GetInt32() % (int.MaxValue - length + 1);
        TestLibrary.TestFramework.BeginScenario(c_TEST_DESC);
        try
        {
            operandStack.CopyTo(values, startIndex);
            errorDesc = "ArgumentException is not thrown as expected when arrayIndex is " +
                startIndex + ", the length of array is " + values.Length;
            TestLibrary.TestFramework.LogError("011" + " TestId-" + c_TEST_ID, errorDesc);
            retVal = false;
        }
        catch (ArgumentException)
        { }
        catch (Exception e)
        {
            errorDesc = "Unexpected exception: " + e +
                "\narrayIndex is " + startIndex + ", the length of array is " + values.Length;
            TestLibrary.TestFramework.LogError("012" + " TestId-" + c_TEST_ID, errorDesc);
            retVal = false;
        }

        return retVal;
    }
开发者ID:l1183479157,项目名称:coreclr,代码行数:35,代码来源:stackcopyto.cs

示例9: GetValue

            public static double GetValue(Stack<Item> items, Dictionary<char, double> arguments)
            {
                Stack<double> result = new Stack<double>();
                Item[] elements = new Item[items.Count];
                items.CopyTo(elements, 0);

                for (int i = elements.Length - 1; i >= 0; i--)
                {
                    Item element = elements[i];
                    if (element is Number)
                        result.Push(((Number)element).Value);
                    else
                    if (element is Variable)
                    {
                        double value = 0;

                        if (arguments == null)
                            throw new ArgumentException("Variable " + ((Variable)element).Name + " is not found in dictionary!");

                        if (arguments.TryGetValue(((Variable)element).Name, out value))
                            result.Push(value);
                        else
                            throw new ArgumentException("Variable " + ((Variable)element).Name + " is not found in dictionary!");
                    }
                    else
                    {
                        if (element is BinaryOperation)
                        {
                            BinaryOperation operation = (BinaryOperation)element;
                            if (operation.Type == BinaryOperation.BinaryOperationType.divide)
                            {
                                double divider = result.Pop();
                                result.Push(result.Pop() / divider);
                            }
                            else
                            if (operation.Type == BinaryOperation.BinaryOperationType.multiply)
                                result.Push(result.Pop() * result.Pop());
                            else
                            if (operation.Type == BinaryOperation.BinaryOperationType.plus)
                            {
                                double value = result.Pop();
                                if (result.Count == 0)
                                    result.Push(value);
                                else
                                    result.Push(result.Pop() + value);
                            }
                            else
                                if (operation.Type == BinaryOperation.BinaryOperationType.minus)
                            {
                                double value = result.Pop();
                                if (result.Count == 0)
                                    result.Push(-value);
                                else
                                    result.Push(result.Pop() - value);
                            }
                            else
                                if (operation.Type == BinaryOperation.BinaryOperationType.power)
                            {
                                double pow = result.Pop();
                                result.Push(Math.Pow(result.Pop(), pow));
                            }
                        }
                        else
                        if (element is UnaryOperation)
                        {
                            UnaryOperation operation = (UnaryOperation)element;
                            if (operation.Type == UnaryOperation.UnaryOperationType.cos)
                                result.Push(Math.Cos(result.Pop()));
                            else
                                if (operation.Type == UnaryOperation.UnaryOperationType.sin)
                                result.Push(Math.Sin(result.Pop()));
                            else
                                if (operation.Type == UnaryOperation.UnaryOperationType.log)
                                result.Push(Math.Log(result.Pop()));
                        }
                    }
                }

                return result.Pop();
            }
开发者ID:puninvv,项目名称:university,代码行数:80,代码来源:Derivator.cs

示例10: NegTest2

    public bool NegTest2()
    {
        bool retVal = true;

        const string c_TEST_ID = "N002";
        string c_TEST_DESC = "NegTest2: arrayIndex is less than zero.";
        string errorDesc;

        int[] values = new int[TestLibrary.Generator.GetInt32() % (c_MAX_ARRAY_LENGTH + 1)];
        int startIndex = -1 * TestLibrary.Generator.GetInt32() - 1;
        TestLibrary.TestFramework.BeginScenario(c_TEST_DESC);
        try
        {
            Stack<int> operandStack = new Stack<int>();
            operandStack.CopyTo(values, startIndex);
            errorDesc = "ArgumentOutOfRangeException is not thrown as expected when arrayIndex is " + 
                startIndex + ".";
            TestLibrary.TestFramework.LogError("007" + " TestId-" + c_TEST_ID, errorDesc);
            retVal = false;
        }
        catch (ArgumentOutOfRangeException)
        { }
        catch (Exception e)
        {
            errorDesc = "Unexpected exception: " + e +
                "\narrayIndex is " + startIndex + ".";
            TestLibrary.TestFramework.LogError("008" + " TestId-" + c_TEST_ID, errorDesc);
            retVal = false;
        }

        return retVal;
    }
开发者ID:l1183479157,项目名称:coreclr,代码行数:32,代码来源:stackcopyto.cs

示例11: NegTest3

    public bool NegTest3()
    {
        bool retVal = true;

        const string c_TEST_ID = "N003";
        string c_TEST_DESC = "NegTest3: The number of elements in the source Stack is greater than the available space from arrayIndex to the end of the destination array.";
        string errorDesc;

        int[] operands = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
        Stack<int> operandStack = new Stack<int>((IEnumerable<int>)operands);
        int[] values = new int[TestLibrary.Generator.GetInt32() % (operandStack.Count)];
        int startIndex = 0;
        TestLibrary.TestFramework.BeginScenario(c_TEST_DESC);
        try
        {
            operandStack.CopyTo(values, startIndex);
            errorDesc = "ArgumentException is not thrown as expected when arrayIndex is " +
                startIndex + ", the length of array is " + values.Length;
            TestLibrary.TestFramework.LogError("009" + " TestId-" + c_TEST_ID, errorDesc);
            retVal = false;
        }
        catch (ArgumentException)
        { }
        catch (Exception e)
        {
            errorDesc = "Unexpected exception: " + e +
                "\narrayIndex is " + startIndex + ", the length of array is " + values.Length;
            TestLibrary.TestFramework.LogError("010" + " TestId-" + c_TEST_ID, errorDesc);
            retVal = false;
        }

        return retVal;
    }
开发者ID:l1183479157,项目名称:coreclr,代码行数:33,代码来源:stackcopyto.cs

示例12: Prit

        private static void Prit(Stack<string> path, int offset, int counterFound)
        {
            Console.SetCursorPosition(0, offset + counterFound);

            string[] foundPath = new string[path.Count];
            path.CopyTo(foundPath, 0);

            for (int i = foundPath.Length - 2; i >= 0; i--)
            {
                Console.Write(foundPath[i]);
            }
            Console.WriteLine();
        }
开发者ID:NikolayKostadinov,项目名称:Homeworks,代码行数:13,代码来源:Program.cs

示例13: StringInStack

 //查询栈中所有元素
 private string StringInStack(Stack<char> stack)
 {
     string temp = "";
     char[] chars = new char[stack.Count];
     stack.CopyTo(chars, 0);
     for (int i = 0; i < chars.Length; i++)
     {
         temp += chars[i];
     }
     return temp;
 }
开发者ID:softexplorer,项目名称:sun,代码行数:12,代码来源:WordAnalyser.cs

示例14: CopyingToMultiDimArrayThrows

 public static void CopyingToMultiDimArrayThrows()
 {
     Stack stack = new Stack();
     stack.Push("hey");
     Assert.Throws<ArgumentException>(() => stack.CopyTo(new Object[8, 8], 0));
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:6,代码来源:StackBasicTests.cs

示例15: ComputeSmithWaterman

        // returns the alignment score
        public int ComputeSmithWaterman()
        {
            for (int i = 0; i < one.Length; i++) {
                for (int j = 0; j < two.Length; j++) {
                    gap = o + (l - 1) * e;
                    if (i != 0 && j != 0) {
                        if (one[i] == two[j]) {
                            // match
                            // reset l
                            l = 0;
                            matrix[i, j] = Math.Max(0, Math.Max(
                                            matrix[i - 1, j - 1] + match, Math.Max(
                                                            matrix[i - 1, j] + gap,
                                                            matrix[i, j - 1] + gap)));
                        } else {
                            // gap
                            l++;
                            matrix[i, j] = Math.Max(0, Math.Max(
                                            matrix[i - 1, j - 1] + gap, Math.Max(
                                                            matrix[i - 1, j] + gap,
                                                            matrix[i, j - 1] + gap)));

                        }
                    }
                }
            }

            // find the highest value
            int longest = 0;
            int iL = 0, jL = 0;
            for (int i = 0; i < one.Length; i++) {
                for (int j = 0; j < two.Length; j++) {
                    if (matrix[i, j] > longest) {
                        longest = matrix[i, j];
                        iL = i;
                        jL = j;
                    }
                }
            }

            // Backtrack to reconstruct the path
            int ii = iL;
            int jj = jL;
            Stack<String> actions = new Stack<String>();

            while (ii != 0 && jj != 0) {
                // diag case
                if (Math.Max(matrix[ii - 1, jj - 1],
                                Math.Max(matrix[ii - 1, jj], matrix[ii, jj - 1])) == matrix[ii - 1, jj - 1]) {
                    actions.Push("align");
                    //Console.WriteLine("a");
                    ii = ii - 1;
                    jj = jj - 1;
                    // left case
                } else if (Math.Max(matrix[ii - 1, jj - 1],
                                Math.Max(matrix[ii - 1, jj], matrix[ii, jj - 1])) == matrix[ii, jj - 1]) {
                    actions.Push("insert");
                    //Console.WriteLine("i");
                    jj = jj - 1;
                    // up case
                } else {
                    actions.Push("delete");
                    //Console.WriteLine("d");
                    ii = ii - 1;
                }
            }

            string alignOne = "";
            string alignTwo = "";
            string[] tmp = new string[actions.Count];
            actions.CopyTo(tmp, 0);

            Stack<string> backActions = new Stack<string>(tmp);
            for (int z = 0; z < one.Length; z++) {
                alignOne = alignOne + one[z];
                if (actions.Count > 0) {
                    String curAction = actions.Pop();
                    // Console.WriteLine(curAction);
                    if (curAction.Equals("insert")) {
                        alignOne = alignOne + "-";
                        while (actions.Peek().Equals("insert")) {
                            alignOne = alignOne + "-";
                            actions.Pop();
                        }
                    }
                }
            }

            for (int z = 0; z < two.Length; z++) {
                alignTwo = alignTwo + two[z];
                if (backActions.Count > 0) {
                    String curAction = backActions.Pop();
                    if (curAction.Equals("delete")) {
                        alignTwo = alignTwo + "-";
                        while (backActions.Peek().Equals("delete")) {
                            alignTwo = alignTwo + "-";
                            backActions.Pop();
                        }
                    }
//.........这里部分代码省略.........
开发者ID:GrowingData,项目名称:Utilities,代码行数:101,代码来源:SmithWaterman.cs


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