I cannot get my head around this. I have created a generic Link List class, and Link class and I'm now trying to create a function within the LinkList class that will insert the inputted variable into the correct spot within the linklist. Here is my code so far:
The code has looked quite different, quite a few times. I've tried endless possibilities. I just cannot insert 'item' in the correct spot within the linklist
Any help is greatlyyyyyyyy appreciated!! :drunk:
C#:
public void InsertInOrder(T item)
{
// is list in non-descending
LinkGen<T> temp = list;
if (temp == null)
{
AddItem(item);
}
else
{
while (item.CompareTo(temp.Data) > 0)
{
temp = temp.Next;
}
list = new LinkGen<T>(item, list);
}
}
The code has looked quite different, quite a few times. I've tried endless possibilities. I just cannot insert 'item' in the correct spot within the linklist
Any help is greatlyyyyyyyy appreciated!! :drunk: