0% found this document useful (0 votes)
86 views1 page

20.1 39. Issorted PDF

The document defines a struct called Array to represent arrays, with fields for the elements, size, and length. It includes functions to display the elements of an Array and check if an Array is sorted by iterating through the elements and comparing adjacent values, returning 0 if any element is greater than the next element or 1 if all elements are in sorted order. The main function passes an initialized Array to the isSorted function, prints the return value to indicate if it is sorted, and then displays the elements.

Uploaded by

Md Asif Alam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
86 views1 page

20.1 39. Issorted PDF

The document defines a struct called Array to represent arrays, with fields for the elements, size, and length. It includes functions to display the elements of an Array and check if an Array is sorted by iterating through the elements and comparing adjacent values, returning 0 if any element is greater than the next element or 1 if all elements are in sorted order. The main function passes an initialized Array to the isSorted function, prints the return value to indicate if it is sorted, and then displays the elements.

Uploaded by

Md Asif Alam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Checking if Array is Sorted

#include<stdio.h>
#include<stdlib.h>
struct Array
{
int A[10];
int size;
int length;
};
void Display(struct Array arr)
{
int i;
printf("\nElements are\n");
for(i=0;i<arr.length;i++)
printf("%d ",arr.A[i]);
}

int isSorted(struct Array arr)


{
int i;
for(i=0;i<arr.length-1;i++)
{
if(arr.A[i]>arr.A[i+1])
return 0;
}
return 1;
}

int main()
{

struct Array arr1={{2,3,9,16,18,21,28,32,35},10,9};


printf("%d",isSorted(arr1));
Display(arr1);
return 0;
}

You might also like