My program is supposed to sort a doubly linked link alphabetically, and each node contains a single word string, my program crashes when it gets this far, whats missing??

void List::sortAlpha(){
Node * temp;
temp=start;
while(temp!=NULL){
string a=temp->word;
string b=temp->next->word;
string c;
if(a[0]<b[0]){
c = a;
a = b;
b = c;
}
else{
c = b;
b = a;
a = c;
}
temp=temp->next;
}
}

A few things here .... First, wrap your code in code tags. It makes it easier to read.

Secondly, what kind of error are you getting?

Thirdly, I noticed that your while loop runs until temp != Null but two lines down from that you try to reference temp->next->word. If temp is the last item in the list, you are trying to reference data on a node that doesn't exist. temp->next = null but you are trying to get temp->next->word.

finally, you aren't actually sorting nodes in the function. You are just moving string values around the variables a, b, and c. It's not doing anything.

commented: good answers :) +33
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.