### Basic Data Structures: Linked Lists

A linked list is a data structure consisting nodes which together represent a sequence. Each node contains at least data and a reference to the next node. Hours and hours have been spent writing about linked lists, so no point on rehashing it again. For more information, you can use the Google machine or check Wikipedia’s page on the subject. http://en.wikipedia.org/wiki/Linked_list

### Now the code

#### Declaring the node

Nothing fancy, straight forward thing
public class Node
{
public object data;
public Node next;
public Node(object data)
{
this.data = data;
}
}

{
Node current;
{

{
current = n;
}
else
{
current.next = n;
current = current.next;
}
}
public void InsertAtTop(Node n)
{
if (n == null)
{
return;
}
n.next = current;
}
public void Insert(Node n)
{
if (n == null) { return; }

if ((int)current.data >= (int)n.data)
{
n.next = current;
return;
}
current = current.next;
while (current != null)
{
if ((int)current.data <= (int)n.data)
{
n.next = current.next;
current.next = n;
return;
}
current = current.next;
}
current.next = n;
}
public string ReverseAndParse()
{
string temp = “”;
while (current.next != null)
{
temp = string.Concat(current.data.ToString(), temp);
current = current.next;
}
temp = string.Concat(current.data.ToString(), temp);
return temp;
}
public string Parse()
{
string temp = “”;
while (current.next != null)
{
temp = string.Concat(temp, current.data.ToString());
current = current.next;
}
temp = string.Concat(temp, current.data.ToString());
return temp;
}
public void DisplayItems()
{
while (n.next != null)
{
Console.WriteLine(“Node : {0}”, n.data);
n = n.next;
}
//display the lastone
Console.WriteLine(“Node : {0}”, n.data);
}
public void RemoveDuplicates()
{
while (current.next != null)
{
Node n = current;
while (n.next != null)
{
if (n.next.data.Equals(current.data))
{
n.next = n.next.next;
}
else
{
n = n.next;
}
}
current = current.next;
}
}
public Node Split(object x, Node node)
{
Node tail = node;
while (node.next != null)
{
Node next = node.next;
if ((int)node.data < (int)x)
{
}
else
{
tail.next = node;
tail = node;
}
node = next;
}

if ((int)node.data < (int)x)
{
}
else
{
tail.next = node;
tail = node;
}
tail.next = null;

}
public Node addNodes(Node first, Node second, int CarryOver)
{
Node n = new Node(CarryOver);
int value = (int)(first == null ? 0 : (int)first.data) + (second == null ? 0 : (int)second.data) + CarryOver;
n.data = (value >= 10 ? (value – 10) : value);
if (first != null || second != null)
{
Node New = (addNodes((first.next == null ? null : first.next), (second.next == null ? null : second.next), (value / 10)));
if (New != null)
{
}
}
return n;
}
public Node BreakAndFix()
{

Node breaker = current.next.next;
while (current.next != null)
{
current = current.next;
}
while (fast != null && fast.next != null)
{
slow = slow.next;
fast = fast.next.next;
if (slow.Equals(fast))
{
break;
}
}
if (fast == null || fast.next == null)
{
return null;
}