-
Notifications
You must be signed in to change notification settings - Fork 0
/
prog3.c
60 lines (57 loc) · 1.14 KB
/
prog3.c
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
52
53
54
55
56
57
58
59
60
#include <stdio.h>
#include <stdlib.h>
#define SIZE 1024
void merge(int a[], int l, int m, int r)
{
int i, j, k, b[SIZE];
i = l;
j = m + 1;
k = l;
while (i <= m && j <= r)
{
if (a[i] < a[j])
{
b[k++] = a[i++];
}
else
b[k++] = a[j++];
}
while (i <= m)
b[k++] = a[i++];
while (j <= r)
b[k++] = a[j++];
for (i = l; i <= r; i++)
a[i] = b[i];
}
void mergesort(int a[], int l, int r)
{
if (l < r)
{
int m = (l + r) / 2;
mergesort(a, l, m);
mergesort(a, m + 1, r);
merge(a, l, m, r);
}
}
int main()
{
int n, a[SIZE], i, j, flag = 0;
printf("\nEnter the number of elements\n");
scanf("%d", &n);
printf("\nEnter the elements\n");
for (i = 0; i < n; i++)
scanf("%d", &a[i]);
mergesort(a, 0, n - 1);
for (i = 0; i < n; i++)
printf("%d\t", a[i]);
for (i = 0; i < n - 1; i++)
{
if (a[i] == a[i + 1])
{
printf("\nThe array is not unique");
flag = 1;
}
}
if (flag = 0)
printf("\nThe array is unique");
}