I'm trying to implement bubble sort using linked list and here is my code:
itr = head;
for (int j = 1; j < size; j++)
{
for (int k = 0; k < size - 1; k++)
{
if (itr.item > itr.next.item)
{
t = itr.item;
itr.item = itr.next.item;
itr.next.item = t;
}
itr = itr.next;
}
}
the line
if (itr.item > itr.next.item)
gives the null pointer exception. I don't know what is wrong with my code. and size is the number of nodes in the linked list.