gur111 icon

isListSorted and getListLength for Ex1

gur111 | PRO | 04/09/20 06:17:14 PM UTC | 0 ⭐ | 722 👁️ | Never ⏰ | []
C |

460 B

|

None

|

0 👍

/

0 👎

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