isListSorted and getListLength for Ex1
int getListLength(Node list) {
int count = 0;
while (list) {
count++;
list = list->next;
}
return count;
}
bool isListSorted(Node list) {
if (list == NULL) {
return true;
}
int prev = list->x;
list = list->next;
while (list != NULL) {
if (prev > list->x) {
return false;
}
prev = list->x;
list = list->next;
}
return true;
}
Comments