using System;
using System.Collections.Generic;
namespace CourseWork
{
public class LinkedList
{
private Node head;
private int count;
public LinkedList()
{
this.head = null;
this.count = 0;
}
public bool Empty
{
get { return this.count == 0; }
}
public int Count
{
get { return this.count; }
}
public int Add(int index, int obj)
{
if (index < 0)
throw new ArgumentOutOfRangeException("Index: " + index);
if (index > count)
index = count;
Node current = this.head;
if (this.Empty || index == 0)
{
this.head = new Node(obj, this.head);
}
else
{
for (int i = 0; i < index - 1; i++)
current = current.Next;
current.Next = new Node(obj, current.Next);
}
count++;
return obj;
}
public int Add(int obj)
{
return this.Add(count, obj);
}
public void Print()
{
Console.Write(head.Data + " -> ");
if (head.Next != null)
{
head = head.Next;
Print();
}
}
public void Sort()
{
//Node current = this.head;
if(head.Data > head.Next.Data)
{
Node temp = this.head;
temp.Next = head.Next;
}
}
}
}