Linked List in C#
This might interest you: Pro C# 2010 and the .NET 4 Platform, Fifth Edition
This is my class for C# linked lists. Simple as that.
-
using System;
-
using System.Collections.Generic;
-
using System.Text;
-
using System.Runtime.InteropServices;
-
-
namespace nsLinkedList
-
{
-
public class LinkedList
-
{
-
public string line;
-
-
public LinkedList prev = null;
-
public LinkedList next = null;
-
}
-
-
public class LinkedListFuncs
-
{
-
public LinkedList Push(string line, LinkedList list)
-
{
-
temp.line = line;
-
temp.prev = null;
-
temp.next = null;
-
-
if (list == null)
-
return temp;
-
-
LinkedList tmppek = list;
-
-
while (tmppek.next != null)
-
tmppek = tmppek.next;
-
-
tmppek.next = temp;
-
temp.prev = tmppek;
-
-
return list;
-
}
-
-
public bool Replace(string oldstr, string newstr, LinkedList list)
-
{
-
LinkedList tmppek = list;
-
-
while (tmppek != null)
-
{
-
if (tmppek.line == oldstr)
-
break;
-
tmppek = tmppek.next;
-
}
-
-
if (tmppek != null)
-
{
-
tmppek.line = newstr;
-
return true;
-
}
-
-
return false;
-
}
-
-
public LinkedList Remove(LinkedList remove, LinkedList list)
-
{
-
LinkedList tmppek = list;
-
-
while (tmppek != remove)
-
tmppek = tmppek.next;
-
-
if (tmppek.prev == null)
-
{
-
list = list.next;
-
list.prev = null;
-
}
-
else if (tmppek.next == null)
-
{
-
tmppek.prev.next = null;
-
}
-
else
-
{
-
tmppek.prev.next = tmppek.next;
-
tmppek.next.prev = tmppek.prev;
-
}
-
-
tmppek = null;
-
-
return list;
-
}
-
-
public LinkedList Free(LinkedList list)
-
{
-
if (list == null)
-
return null;
-
-
LinkedList tmppek = list;
-
-
while (tmppek.next != null)
-
{
-
tmppek.prev = null;
-
tmppek = tmppek.next;
-
}
-
-
tmppek = null;
-
list = null;
-
-
return list;
-
}
-
-
public LinkedList Find(string findstr, LinkedList list)
-
{
-
LinkedList tmppek = list;
-
-
while (tmppek != null)
-
{
-
if (tmppek.line == findstr)
-
return tmppek;
-
tmppek = tmppek.next;
-
}
-
-
return null;
-
}
-
}
-
}

