i want to implement this in c#, i have my linked list class ready, but problem occurs when i sort the class using this Sort method. How can I give priority to elements, so that the highest priority element dequeue first.
public void Sort()
{
ListNode current=first;
int temp;
for (int i = 0; i < counter; i++)
{
while (current.Next != null)
{
if (current.Data > current.Next.Data)
{
temp = current.Data;
current.Data = current.Next.Data;
current.Next.Data = current.Data;
}
current = current.Next;
}
}
}
I don’t think you have to sort the list like this, just create an insert routine that inserts any new elements in the right spot and your list will always be sorted.
Rgds GJ