C# LinkedList

Date: 2021-08-03
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;

class Program 
{
	static void Main (string[] args) 
	{
		Console.WriteLine ("Hello World!");

		var rand = new Random ();
		var list = new LinkedList<int> ();
		var stack = new Stack<int> ();

		var sw = new Stopwatch ();

		Console.Write ("{0,40}", "Pushing to Stack...");
		sw.Reset ();
		sw.Start ();
		for (int i = 0; i < 100000; i++) {
			stack.Push (rand.Next ());
		}
		sw.Stop ();
		Console.WriteLine ("  Time used: {0,9} ticks", sw.ElapsedTicks);

		var nodes = new LinkedListNode<int>[100000];
		for (int i = 0; i < 100000; i++) {
			nodes[i] = new LinkedListNode<int> (rand.Next ());
		}

		Console.Write ("{0,40}", "Pushing to LinkedList...");

		sw.Reset ();
		sw.Start ();
		for (int i = 0; i < 100000; i++) {
			list.AddFirst (nodes[i]);
		}

		sw.Stop ();
		Console.WriteLine ("  Time used: {0,9} ticks", sw.ElapsedTicks);
	}
}
52270cookie-checkC# LinkedList