lexicographical comparison

I have been trying to a lexicographical comparison with my doubly linked list but I have no idea what to do with it.

here is my code:
1
2
3
4
5
6
7
8
9
10
11


template <class T>
bool List<T>::operator<(const List<T>& rightOp) const
{
 if(head < rightOp.head) return true;
 if(head > rightOp.head) return false;
 if(head->data < rightOp.head->data) return true;
 if(head->data > rightOp.head->data) return false;
 return false;
}


I keep getting a segmentation fault with this. Which is probably from the head->data < rightOp.head->data comparison. Also I'am passing in ints not strings. I've never worked with lexicographical comparison and I'm a confused on what it really is. Can anyone explain to me what a lexicographical comparison means? Thanks.
What your lexicographical comparison should do is check the three cases (less than, greater than, equal) for each element of the list.

Starting with the head, and going over the elements:
Is the lhs's element's data < the rhs's element's data? If so, then end with lhs < rhs.
Is the lhs's element's data > the rhs's element's data? If so, then end with lhs > rhs.
The lhs's element's data must == the rhs's element's data. So, move to the next element for each list.
Alright this what i coded so far:
1
2
3
4
5
6
7
8
template <class T>
bool List<T>::operator<(const List<T>& rightOp) const
{
   if(head->data < rightOp.head->data) return head < rightOp.head;
   if(head->data > rightOp.head->data) return head > rightOp.head;
   if(head->data == rightOp.head->data) return true;
   return false;
}


I'm still get a segmentation fault. I'm guessing my if(head-> == rightOp.head->data) return true; isn't working right. I tried returning false, head->next and rightOp.head->next, and just head->next, but none of them "work". Would returning true mean I am moving to the next element in the lists?
Topic archived. No new replies allowed.