Creating linkedlist manually


LinkedList with CSharp
The difference between a linkedlist and list is proposed by a fellow named Aliostad on stackoverflow.com checked a program that shows a link list to compare the speed between a List and a Linked-List.

static void Main(string[] args)
{

const int N = 1000*1000;
Random r = new Random();
LinkedList linkedList = new LinkedList();
List list = new List();
List> linkedListNodes = new List>();

for (int i = 0; i < N; i++) { list.Add(r.Next()); LinkedListNode linkedListNode = linkedList.AddFirst(r.Next());
if(r.Next() % 997 == 0)
linkedListNodes.Add(linkedListNode);
}

Stopwatch stopwatch = new Stopwatch();

stopwatch.Start();
for (int i = 0; i < 500; i++) { linkedList.AddBefore(linkedListNodes[i], r.Next()); linkedList.Remove(linkedListNodes[i]); } stopwatch.Stop(); Console.WriteLine("LinkedList 500 insert/remove operations: {0}", stopwatch.ElapsedTicks); stopwatch.Reset(); stopwatch.Start(); for (int i = 0; i < 500; i++) { list.Insert(r.Next(0,list.Count), r.Next()); list.RemoveAt(r.Next(0, list.Count)); } stopwatch.Stop(); Console.WriteLine("List 500 insert/remove operations: {0}", stopwatch.ElapsedTicks); Console.Read(); } }

LinkedList 500 insert/remove operations: 10171
List 500 insert/remove operations: 968465

Here we will use our simple program that uses linked list

using System;
using System.Collections.Generic;

class Program
{
static void Main()
{
// creating linked list object
LinkedList mylist = new LinkedList();

mylist.AddLast(“EmployeeID: 1234”);
mylist.AddFirst(“Name:George”);
mylist.AddLast(“Position:Manager”);
mylist.AddLast(“Date and place of birth:Karachi”);

foreach (var myitem in mylist)
{
Console.WriteLine(myitem);
}
}
}

We encourage you to read this post if you have to clear your concepts.This will clear your min.d

post on linked lists

Syed Adeel Ahmed
Syed Adeel Ahmed
Analyst, Programmer, Educationist and Blogger at Technofranchise
Computer Systems Engineer from Sir Syed University Of Engineering & Technology.I am passionate about all types of programming.

Published by

Syed Adeel Ahmed

Computer Systems Engineer from Sir Syed University Of Engineering & Technology.I am passionate about all types of programming.

Leave a Reply