SHOW:
|
|
- or go back to the newest paste.
1 | #include <iostream> | |
2 | #include <string> | |
3 | #include <sstream> | |
4 | ||
5 | using namespace std; | |
6 | ||
7 | bool isSorted(const int list[], int size){ | |
8 | - | for(int i = 0; i < size-1; i++){ |
8 | + | for(int i = 0; i < size-1; i++) |
9 | if(list[i] > list[i+1]) | |
10 | return false; | |
11 | return true; | |
12 | } | |
13 | ||
14 | int main(){ | |
15 | const int MAX_LIST_SIZE = 80; | |
16 | int list[MAX_LIST_SIZE]; | |
17 | int size; | |
18 | string mystr; | |
19 | ||
20 | cout << "Enter list: "; | |
21 | getline(cin, mystr); | |
22 | stringstream ss(mystr); | |
23 | ss >> size; | |
24 | for(int initial = 0; initial < size; initial++){ | |
25 | ss >> list[initial]; | |
26 | } | |
27 | ||
28 | if(isSorted(list, size)) cout << "The list is sorted. << endl; | |
29 | else cout << "The list is not sorted. << endl; | |
30 | return 0; | |
31 | } |