using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WpfApplication2
{
class List
{
private ListElem first;
private ListElem curent;
public void addToStart(float Value)
{
if (first == null)
{
first = new ListElem();
first.data = Value;
}
else
if (first != null)
{
curent = new ListElem();
curent.data = Value;
curent.nextElement = first;
first = curent;
}
}
public void deleteFirst()
{
if (first != null)
{
first = first.nextElement;
}
}
public void addElementTo(float value, int position)
{
if (position == 0)
addToStart(value);
else
{
curent = first;
for (int i = 0; i < position - 1; i++)
{
curent = curent.nextElement;
if (curent == null)
return;
}
curent.nextElement = new ListElem(value, curent.nextElement);
}
}
public void delAt(int position)
{
if (position == 0)
deleteFirst();
else
{
curent = first;
for (int i = 0; i < position - 1; i++)
{
curent = curent.nextElement;
if (curent == null)
return;
}
curent.nextElement = curent.nextElement.nextElement;
}
}
public void DelAtEnd()
{
if (first == null)
return;
if (first.nextElement == null)
{
deleteFirst();
return;
}
curent = first;
while (curent.nextElement.nextElement != null)
{
curent = curent.nextElement;
}
curent.nextElement = null;
}
public void AddToEnd(float value)
{
if (first == null)
addToStart(value);
else
{
curent = first;
while (curent.nextElement != null)
{
curent = curent.nextElement;
}
curent.nextElement = new ListElem();
curent.nextElement.data = value;
}
}
public string ShowAll()
{
string s="";
curent = first;
while (curent != null)
{
s += curent.data.ToString("g") + " ";
curent = curent.nextElement;
}
return s;
}
public void sort()
{
List pos = new List();
List neg = new List();
ListElem thisCurent = first;
while(thisCurent!=null)
{
if (thisCurent.data > 0)
pos.AddToEnd(thisCurent.data);
else
neg.AddToEnd(thisCurent.data);
thisCurent = thisCurent.nextElement;
}
thisCurent = pos.first;
while (thisCurent.nextElement != null)
thisCurent = thisCurent.nextElement;
first = pos.first;
thisCurent.nextElement = neg.first;
}
}
class ListElem
{
public float data;
public ListElem nextElement = null;
public ListElem() { }
public ListElem(float data, ListElem next)
{
this.data = data;
nextElement = next;
}
}
}