so bacicly i have this code in which you cin a number and then an array of this number size example
6
2
4
7
7
9
3
all of them being in an index i of the array like this
2-----0
4-----1
7-----2
7-----3
9-----4
3-----5
so in this code what i want to find if all the elements from index 3 to the end are sorted
if 7 9 3 is sorted using the is sorted funtion like this
is_sorted(v+2+1,v+n-2-1)
so this would be like is_sorted(0+2+1,0+6-2-1)
or is_sorted(3,3)
so it should chek if the 3 elements from index 3 are sorted
bacicly checking if the array 7 9 3 is sorted which is obviosly not true but my code throws 1 instead of 0
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin>>n;
int v[n];
for(int i=0;i<n;i++){
int a;
cin>>a;
v[i]=a;
}
cout<<is_sorted(v+2+1,v+n-2-1);
return 0;
}
Aucun commentaire:
Enregistrer un commentaire