Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

SO LinkedList Question

By: a guest on Apr 27th, 2013  |  syntax: None  |  size: 1.39 KB  |  views: 44  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace LinkedListChecks
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             LinkedList<Temp> linkedList = new LinkedList<Temp>();
  14.             List<Temp> list = new List<Temp>();
  15.             int intLoopCnt = 100;
  16.  
  17.             for (var i = 0; i < intLoopCnt; i++)
  18.             {
  19.                 var a = new Temp(i, i, i, i);
  20.  
  21.                 list.Insert(i / 2, a);
  22.             }
  23.  
  24.             for (var i = 0; i < intLoopCnt; i++)
  25.             {
  26.                 var a = new Temp(i, i, i, i);
  27.  
  28.                 linkedList.AddLast(a);
  29.                 var curNode = linkedList.First;
  30.                
  31.                 for (var k = 0; k < i / 2; k++) // in order to insert a node at the middle of the list we need to find it
  32.                     curNode = curNode.Next;
  33.  
  34.                 linkedList.AddAfter(curNode, a); // insert it after
  35.             }
  36.  
  37.             Console.WriteLine("List count: " + list.Count);
  38.             Console.WriteLine("LinkedList count: " + linkedList.Count);
  39.  
  40.             Console.Read();
  41.         }
  42.  
  43.  
  44.  
  45.     }
  46.  
  47.     class Temp
  48.     {
  49.         public decimal A, B, C, D;
  50.  
  51.         public Temp(decimal a, decimal b, decimal c, decimal d)
  52.         {
  53.             A = a; B = b; C = c; D = d;
  54.         }
  55.     }
  56.  
  57. }