How hard is it to implent bubble sort on
a single linked list ?
By hard I mean, that we will have to write diffrent
code for each private case. Like if the list contains
only two juctions and other case if more. A case for dealing with the head . etc.
Just to be sure that we are talking on the same things
here is a bubble sort on an array :
Code:
void bubble_sort(int arr[], int sarr)
{
int i , j;
for ( i = 0 ; i < sarr - 1 ; ++i )
for ( j = sarr-1 ; j > i ; --j )
if ( arr[j] < arr[j-1] )
swap(arr+j, arr+j-1);
}
By saying "single linked list." Im mean that I have
only one pointer for the next junction. ( there is no
prev pointer).