Advertisement
gur111

isListSorted and getListLength for Ex1

Apr 9th, 2020
424
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.46 KB | None | 0 0
  1. int getListLength(Node list) {
  2.     int count = 0;
  3.  
  4.     while (list) {
  5.         count++;
  6.         list = list->next;
  7.     }
  8.     return count;
  9. }
  10.  
  11. bool isListSorted(Node list) {
  12.     if (list == NULL) {
  13.         return true;
  14.     }
  15.  
  16.     int prev = list->x;
  17.     list = list->next;
  18.  
  19.     while (list != NULL) {
  20.         if (prev > list->x) {
  21.             return false;
  22.         }
  23.         prev = list->x;
  24.         list = list->next;
  25.     }
  26.  
  27.     return true;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement