Update in identification if array is sorted or not

Here the identification process of the array that it is sorted or not was not properly constructed. Addition of the if statement will ensure that a sorted array with duplicate entries can be entered and identified.
pull/758/head
TusharKrSoniTKS 2022-05-19 11:35:05 +05:30 committed by GitHub
parent 25e68800e4
commit 989ed51d6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 1 deletions

View File

@ -52,13 +52,15 @@ int max=-2147483647;
for(int i=0;i<size;i++){ for(int i=0;i<size;i++){
cin>>arr[i]; cin>>arr[i];
// checking if input array is sorted or not // checking if input array is sorted or not
if(arr[i]<max){ if(i!=0){
if(arr[i]<arr[i-1]){
cout<<"Array not sorted"; cout<<"Array not sorted";
return 0; return 0;
}else{ }else{
max=arr[i]; max=arr[i];
} }
} }
}
removeDuplicates(arr,size); removeDuplicates(arr,size);
} }