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


C# LinkedList.AddFirst方法代码示例

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


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

示例1: SumLinkedList1

        private LinkedList<int> SumLinkedList1(LinkedList<int> list1, LinkedList<int> list2)
        {
            LinkedList<int> result = new LinkedList<int>();

            var nodeList1 = list1.First;
            var nodeList2 = list2.First;
            int value = 0;

            while (nodeList1 != null || nodeList2 != null)
            {
                if (nodeList1 != null)
                {
                    value += nodeList1.Value;
                    nodeList1 = nodeList1.Next;
                }

                if (nodeList2 != null)
                {
                    value += nodeList2.Value;
                    nodeList2 = nodeList2.Next;
                }

                result.AddFirst(value % 10);
                value = value / 10;
            }

            if (value != 0)
            {
                result.AddFirst(value);
            }

            return result;
        }
开发者ID:agnet,项目名称:st12,代码行数:33,代码来源:c2_4.cs

示例2: FurnishRooms

 public static void FurnishRooms(LinkedList<RoomNode> roomList, RoomStyle rmstyle, GameObject doorConnector)
 {
     foreach (RoomNode room in roomList) {
             if(room.isCorridor == false)
             {
                 PlatformAssembler asm = room.roomObject.AddComponent<PlatformAssembler>();
                 asm.placeableObjects = rmstyle.placeablePlatforms;
                 LinkedList<PlatformingElement> doors = new LinkedList<PlatformingElement>();
                 foreach(RoomNode neighbor in room.neighbors)
                 {
                     Bounds overl = RoomNode.OverlapBounds(room.roomBounds, neighbor.roomBounds);
                     if(overl.extents.y > 0.01f)
                     {
                         GameObject newDoorPiece = (GameObject) Instantiate(doorConnector, overl.center - Vector3.Scale(Vector3.up, overl.extents), Quaternion.LookRotation(RoomNode.CheckRoomTouch(neighbor.roomBounds, room.roomBounds)));
                         doors.AddFirst(newDoorPiece.GetComponent<PlatformingElement>());
                     }
                     else
                     {
                         GameObject newDoorPiece = (GameObject) Instantiate(doorConnector, overl.center, Quaternion.LookRotation(RoomNode.CheckRoomTouch(neighbor.roomBounds, room.roomBounds)));
                         doors.AddFirst(newDoorPiece.GetComponent<PlatformingElement>());
                     }
                 }
                 if(doors.Count > 1) {
                     PlatformingElement[] starts = new PlatformingElement[doors.Count];
                     int doorind = 0;
                     foreach(PlatformingElement pe in doors)
                     {
                         starts[doorind++] = pe;
                     }
                     asm.ConnectDoorPieces(starts);
                 }
             }
         }
 }
开发者ID:Vorren,项目名称:DunGen,代码行数:34,代码来源:RoomGenerator.cs

示例3: Main

    static void Main()
    {
        var list = new LinkedList<int>();

        list.AddLast(1);
        Console.WriteLine(list);

        list.AddLast(2);
        Console.WriteLine(list);

        list.AddLast(3);
        Console.WriteLine(list);

        list.AddFirst(-1);
        Console.WriteLine(list);

        list.AddFirst(-2);
        Console.WriteLine(list);

        list.AddFirst(-3);
        Console.WriteLine(list);

        Console.WriteLine("Remove First: {0}", list.RemoveFirst().Value);
        Console.WriteLine("Remove Last: {0}", list.RemoveLast().Value);
        Console.WriteLine(list);

        Console.WriteLine("Min: {0}; Max: {1}", list.Min(), list.Max());
        Console.WriteLine("Contains 2: {0}", list.Contains(2));
        Console.WriteLine("Count: {0}", list.Count);
    }
开发者ID:dgrigorov,项目名称:TelerikAcademy-1,代码行数:30,代码来源:Program.cs

示例4: Main

        static void Main(string[] args)
        {
            LinkedList<string> sporcular = new LinkedList<string>();
            sporcular.AddLast("A");
            sporcular.AddLast("B");
            sporcular.AddLast("C");
            sporcular.AddLast("D");
            sporcular.AddLast("E");
            sporcular.AddLast("F");
            sporcular.AddLast("G");
            sporcular.AddLast("H");

            sporcular.Remove("H");
            sporcular.AddFirst("H");

            sporcular.Remove("E");
            sporcular.AddFirst("E");

            sporcular.AddAfter(sporcular.First, "X");

            LinkedListNode<string> c =
                sporcular.Find("C");

            sporcular.AddBefore(c, "Y");

            foreach (string item in sporcular)
            {
                Console.WriteLine(item);
            }
        }
开发者ID:alperkonuralp,项目名称:CSharpOrnekleri,代码行数:30,代码来源:Program.cs

示例5: btnRand_Click

        private void btnRand_Click(object sender, EventArgs e)
        {
            Random r = new Random();
            var sz = r.Next(8, 12);
            int gap = this.ClientSize.Height / sz;
            int width = this.ClientSize.Width;
            LinkedList<PointF> points = new LinkedList<PointF>();

            points.AddFirst(new PointF(width / 2,
                (float)r.NextDouble() * gap));
            for (int i = 1; i < sz - 1; i++)
            {
                bool putOnLeft = r.Next() % 2 == 0;
                var widthOffset = r.NextDouble() * width / 4;
                PointF p = new PointF(
                    (float)(putOnLeft ? width / 2 - widthOffset : width / 2 + widthOffset),
                    (float)(r.NextDouble() * gap + gap * i));
                if (putOnLeft)
                    points.AddFirst(p);
                else
                    points.AddLast(p);
            }
            points.AddFirst(new PointF(width / 2,
                gap * sz - (float)r.NextDouble() * gap));

            vertices = points.ToList();
            reDrawPolygon(vertices);
        }
开发者ID:lk-chen,项目名称:CG,代码行数:28,代码来源:Triangulation.cs

示例6: foreach

        private static int[] Reordenación(int[] la, int[] lb) {
            LinkedList<int> r = new LinkedList<int>();
            bool[] usados = Enumerable.Range(0, lb.Length)
                                      .Select(x => false)
                                      .ToArray();
            int vmin, vmax, imin, imax, i;

            foreach(int val in la.Reverse()) {
                vmax = int.MinValue; imax = -1;
                vmin = int.MaxValue; imin = -1;

                for(i = 0; i < lb.Length; i++) {
                    if(!usados[i]) {
                        if(lb[i] < vmin) {
                            vmin = lb[i];
                            imin = i;
                        }
                        if(lb[i] > vmax) {
                            vmax = lb[i];
                            imax = i;
                        }
                    }
                }

                if(val > vmax) {
                    r.AddFirst(vmin);
                    usados[imin] = true;
                } else {
                    r.AddFirst(vmax);
                    usados[imax] = true;
                }
            }

            return r.ToArray();
        }
开发者ID:gorkinovich,项目名称:MTP,代码行数:35,代码来源:Ejercicio101.cs

示例7: SearchHelperMethods_AddsToOpenSetInOrder

 public void SearchHelperMethods_AddsToOpenSetInOrder()
 {
     var t = new BestFirst_Accessor();
     var state1 = new List<int>(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, Node.SPACE, 15 });
     var node1 = new Node()
     {
         State = state1,
         FValue = HeuristicFunctions.number_of_tiles_out_of_place(state1)
     };
     var state2 = new List<int>(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, Node.SPACE, 14, 15 });
     var node2 = new Node()
     {
         State = state2,
         FValue = HeuristicFunctions.number_of_tiles_out_of_place(state2)
     };
     var state3 = new List<int>(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 12, Node.SPACE, 14, 15 });
     var node3 = new Node()
     {
         State = state3,
         FValue = HeuristicFunctions.number_of_tiles_out_of_place(state3)
     };
     var param = new LinkedList<Node>();
     param.AddFirst(node1);
     param.AddFirst(node2);
     param.AddFirst(node3);
     t.AddToOpenSet(param);
     Assert.AreEqual(node1.FValue, t.OpenSet.First.Value.FValue);
     Assert.AreEqual(node3.FValue, t.OpenSet.Last.Value.FValue);
 }
开发者ID:simplecoder,项目名称:15PuzzleSolver,代码行数:29,代码来源:SearchHelperMethodsTest.cs

示例8: Main

    // Implement the data structure linked list. 
    public static void Main()
    {
        var linkedList = new LinkedList<string>();

        linkedList.AddFirst("first");
        linkedList.AddLast("second");
        Console.WriteLine(string.Join(", ", linkedList));

        linkedList.Clear();
        linkedList.AddLast("second");
        linkedList.AddFirst("first");
        Console.WriteLine(string.Join(", ", linkedList));

        string value = "first";
        Console.WriteLine("List contains \"{0}\": {1}", value, linkedList.Contains(value));

        Console.WriteLine("List contains {0} item(s)", linkedList.Count);

        var item = linkedList.Find("second");
        Console.WriteLine(item);

        linkedList.Remove("first");
        Console.WriteLine(string.Join(", ", linkedList));

        linkedList.Remove("second");
        Console.WriteLine("List contains {0} item(s): {1}", linkedList.Count, string.Join(", ", linkedList));

        linkedList.AddFirst("second");
        linkedList.AddFirst("first");
        linkedList.AddLast("third");
        Console.WriteLine(string.Join(", ", linkedList));

        linkedList.Remove("second");
        Console.WriteLine(string.Join(", ", linkedList));
    }
开发者ID:MarKamenov,项目名称:TelerikAcademy,代码行数:36,代码来源:LinkedListTest.cs

示例9: FindNullDefines

        //new
        public static IEnumerable<string> FindNullDefines(UnifiedBlock codeObj)
        {
            var binaryExpressions =
                    codeObj.Descendants<UnifiedBinaryExpression>();
            var definition = codeObj.Descendants<UnifiedVariableDefinition>();
            var nameList = new LinkedList<string>();
            foreach (var def in definition) {
                var nullDefinition = def.InitialValue as UnifiedNullLiteral;
                if (nullDefinition != null) {
                    Console.WriteLine("{0} defines null", def.Name.Name);
                    nameList.AddFirst(def.Name.Name);
                }
            }

            foreach (var be in binaryExpressions) {
                if (be.Operator.Kind == UnifiedBinaryOperatorKind.Assign) {
                    var right = be.RightHandSide as UnifiedNullLiteral;
                    var nullId = be.LeftHandSide as UnifiedVariableIdentifier;
                    if (right != null && nullId != null) {
                        Console.WriteLine("{0} will be null", nullId.Name);
                        nameList.AddFirst(nullId.Name);
                    }
                }
            }
            return nameList;
        }
开发者ID:UnicoenProject,项目名称:UniFindBugs,代码行数:27,代码来源:DefUseAnalyzer.cs

示例10: Add

        public static string Add(string n1, string n2)
        {
            int jw = 0;
            LinkedList<char> list = new LinkedList<char>();
            int l = Math.Max(n1.Length, n2.Length);
            for (int i = 0; i < l; i++)
            {
                int i2;
                int i1;
                if (i >= n2.Length)
                    i2 = 0;
                else
                    i2 = n2[n2.Length - 1 - i] - '0';
                if (i >= n1.Length)
                    i1 = 0;
                else
                    i1 = n1[n1.Length - 1 - i] - '0';
                int sum = i1 + i2 + jw;
                if (sum >= 10)
                    jw = 1;
                else
                    jw = 0;

                list.AddFirst((char)(sum % 10 + '0'));
            }
            if (jw > 0)
                list.AddFirst('1');
            return new string(list.ToArray());
        }
开发者ID:card323,项目名称:algorithms,代码行数:29,代码来源:Program.cs

示例11: HeapSort

        public int[] HeapSort(int[] array)
        {
            Heap heap = new Heap(array); // build max heap is called inside constructor
            LinkedList<int> ret = new LinkedList<int>();

            for (int i = heap.Length; i >= 2; i--)
            {
                // this is optional, you can put the element in a return
                // structure. I choosed the linkedlist, where I add the root
                // at the beginning.
                // If I change to AddLast I will get the descOrder
                ret.AddFirst(heap[1]);

                // swap, putting the root(biggest element) at the end, at some place that length--
                // will disconsider the element
                int temp = heap[1];
                heap[1] = heap[i];
                heap[i] = temp;
                heap.Length--;

                // now call the max heapify with the new root and disconsidering the previous root
                heap.MaxHeapify(1);
            }

            ret.AddFirst(heap[1]); // add what the loop dont touch

            return ret.ToArray();
        }
开发者ID:garcialuigi,项目名称:AlgorithmsCSharp,代码行数:28,代码来源:Program.cs

示例12: getMyLinkedList

 public LinkedList<String> getMyLinkedList()
 {
     LinkedList<String> link = new LinkedList<String> ();
     link.AddFirst ("CCC");
     link.AddLast ("AAA");
     link.AddFirst ("BBB");
     return link;
 }
开发者ID:ahirugumi,项目名称:CSharp-Study,代码行数:8,代码来源:MyDictonaryClass.cs

示例13: AddFirstTest

 public void AddFirstTest()
 {
     LinkedList<int> list = new LinkedList<int>();
     list.AddFirst(1);
     list.AddFirst(2);
     list.AddFirst(3);
     CollectionAssert.AreEqual(new [] { 3, 2, 1 }, list);
 }
开发者ID:jeroenkoknl,项目名称:Kok.Collections,代码行数:8,代码来源:LinkedListTest.cs

示例14: LinkedListAddFirst

        public void LinkedListAddFirst()
        {
            LinkedList<int> list = new LinkedList<int>();
            list.AddFirst(7);
            list.AddFirst(5);
            list.AddFirst(3);

            Assert.AreEqual(3, list.Head.Value);
        }
开发者ID:rich-staackmann,项目名称:CSharp,代码行数:9,代码来源:UnitTest1.cs

示例15: Solve

    // Looks like I ended up with the typical sliding-window deque solution. Here's an example for k = 3:
    // 1 3 2 8 4 7 2, initialize left looking dominators like {3, 2}. These dominate everything to their
    // left until a bigger dominator. Leftmost dominator goes to max value for subarray.
    // [1 3 2] 8 4 7 2, {3, 2}
    // 1 [3 2 8] 4 7 2, {8}, lost 1 but it wasn't a dominator, gained 8 and it dominates everything, kills 3 and 2.
    // 1 3 [2 8 4] 7 2, {8, 4}, lost 3 but wasn't a dominator, gained 4 which dominates til 8.
    // 1 3 2 [8 4 7] 2, {8, 7}, lost 2 but wasn't a dominator, gained 7 which kills 4 and domaintes til 8.
    // 1 3 2 8 [4 7 2], {7, 2}, lost 8 so pop it off, gained 2 which dominates til 7.
    // I say dominate because if you're an element and there's an element in your sliding window to your right
    // that's greater than you (dominating you), you're never going to be the max for any of your remaining subarrays.
    // That dominating element to your right will always be there until you're kicked out of the window.
    // When a big number slides in it can dominate all of the dominators and be the only one left; the existing
    // dominators would be to its left so they'd never be able to be the max for any remaining subarrays.
    // We have to keep track of the dominators to the right of other, larger dominators because those other dominators
    // are going to slide out before the ones to their right, and we need to know where to pick up from. It should be
    // clear the dominators are always sorted, descending, from left to right. Dominators could be thought of recursively
    // as greatest element in subarray, followed by greatest element in subarray to that element's right, etc. O(n)
    // because we add or remove an array element from the dominators at most one time.
    public static int[] Solve(int[] array, int k)
    {
        if (k == array.Length) return new[] { array.Max() };
        if (k == 1) return array;

        // Initializing the dominators for the first subarray. Gotta have the rightmost, then the next to the left that's
        // larger than (or equal to) it, and so on. Equal to because we need the next one after an equal one is popped off.
        var leftLookingDominators = new LinkedList<int>();
        leftLookingDominators.AddFirst(array[k - 1]);

        for (int i = k - 2; i >= 0; --i)
        {
            if (array[i] >= leftLookingDominators.Last.Value)
            {
                leftLookingDominators.AddLast(array[i]);
            }
        }

        // Each iteration we're looking at the next subarray, slid over from the previous. We lose an element during the
        // slide which might've been the leftmost dominator (the leftmost dominator is the only one that can be lost). We
        // gain an element which might start dominating everything, or just some dominators til hitting some dominator to its
        // left that's greater than it, or just itself. Don't have to worry about dominators ever becoming empty, because
        // base case handled above. Even for k = 2, if there's only 1 dominator going in to the next iteration, it must be
        // the rightmost element of the previous subarray, so it's not going to get popped off the end until the next next iteration.
        int subarrayCount = array.Length - k + 1;
        int[] subarrayMaximums = new int[subarrayCount];
        subarrayMaximums[0] = leftLookingDominators.Last.Value;

        for (int i = 1, j = k; i < subarrayCount; ++i, ++j)
        {
            int lostLeftValue = array[i - 1];
            int gainedRightValue = array[j];

            if (lostLeftValue == leftLookingDominators.Last.Value)
            {
                leftLookingDominators.RemoveLast();
            }

            if (gainedRightValue > leftLookingDominators.Last.Value)
            {
                leftLookingDominators.Clear();
                leftLookingDominators.AddFirst(gainedRightValue);
            }
            else
            {
                while (gainedRightValue > leftLookingDominators.First.Value)
                {
                    leftLookingDominators.RemoveFirst();
                }
                leftLookingDominators.AddFirst(gainedRightValue);
            }

            subarrayMaximums[i] = leftLookingDominators.Last.Value;
        }

        return subarrayMaximums;
    }
开发者ID:davghouse,项目名称:SPOJ,代码行数:75,代码来源:ARRAYSUB.cs


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