Problem. Bubble sort in a linked list.
I have this code, and crash when i try to sort
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
void ListaServicios::OrdenarBurbuja(){
curr=first;
bool sort=true;
for(; sort; ) {
sort=false;
for(curr; curr->sig != NULL; curr=curr->sig) {
if(curr->datos.name > curr->sig->datos.name) {
temp->datos = curr->sig->datos;
curr->sig->datos = curr->datos;
curr->datos = temp->datos;
sort=true;
}
}
}
}
|
what is wrong?
Where are curr and first declared and defined?
You could be dereferencing a null pointer if they aren't set up correctly.
Do you get an error when running the program or does it just hang? A bit more code would help to get to the bottom of the problem.
Topic archived. No new replies allowed.