Implementation of merge sort algorithm.
More...
#include <stdio.h>
#include <stdlib.h>
|
void | swap (int *a, int *b) |
| Swap two integer variables.
|
|
void | merge (int *a, int l, int r, int n) |
| Perform merge of segments.
|
|
void | merge_sort (int *a, int n, int l, int r) |
| Merge sort algorithm implementation.
|
|
int | main (void) |
| Main function.
|
|
Implementation of merge sort algorithm.
◆ main()
Main function.
107{
108 int *a, n, i;
109 printf("Enter Array size: ");
110 scanf("%d", &n);
111 if (n <= 0)
112 {
113 printf("Array size must be Greater than 0!\n");
114 return 1;
115 }
116 a = (
int *)
malloc(n *
sizeof(
int));
117 if (a == NULL)
118 {
119 printf("Can't Malloc! Please try again.");
120 return 1;
121 }
122 for (i = 0; i < n; i++)
123 {
124 printf("Enter number[%d]: ", i);
125 scanf("%d", &a[i]);
126 }
127
129 printf("Sorted Array: ");
130 for (i = 0; i < n; i++)
131 {
132 printf("%d ", a[i]);
133 }
134 printf("\n");
135
137
138 return 0;
139}
void merge_sort(int *a, int n, int l, int r)
Merge sort algorithm implementation.
Definition merge_sort.c:87
#define malloc(bytes)
This macro replace the standard malloc function with malloc_dbg.
Definition malloc_dbg.h:18
#define free(ptr)
This macro replace the standard free function with free_dbg.
Definition malloc_dbg.h:26