-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.c
More file actions
51 lines (42 loc) · 986 Bytes
/
Copy pathmain.c
File metadata and controls
51 lines (42 loc) · 986 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <stdio.h>
#include <stdlib.h>
#include<stdbool.h>
int Ecart(int *T,int size);
bool Test_Sort(int *T, int size );
int main()
{
int t[]={1,2,3,3,4,6,7};
bool flag = Test_Sort(t,7);
if(flag) printf("Sorted :)");
else
printf("NOT Sorted ): ");
return 0;
}
/// this function show the signe between two cases in the array
int Ecart(int *t,int size){
int i,d;
i=0;
d=t[1]-t[0];
while(i<size-1 && d==0)
{
d = t[i+1] - t[i];
i++;
}
return d;
}
bool Test_Sort(int *T, int size )
{
int d;
d=Ecart(T,size);
if(d==0) return true; /// all the numbers are equal in the array
for(int i = 0 ; i<size-2 ; i++)
{
if((d>0 && T[i+1]-T[i] < 0 )|| (d<0 && T[i+1]-T[i]>0 ))
/* for exemple : if we have t[]={1,2,3,4,5} so here
d=t[1]-t[0] so d==1 and " 1>0 "
in this case we must to check with for loop if the diffrence between two elements are negative
*/
return false;
}
return true;
}