Skip to content
Snippets Groups Projects
Commit 060652e9 authored by 13513010's avatar 13513010
Browse files

Insertion Function and MPI

parent 51486e90
No related merge requests found
...@@ -2,20 +2,12 @@ ...@@ -2,20 +2,12 @@
/* insertion sort ascending order */ /* insertion sort ascending order */
#include <stdio.h> #include <stdio.h>
#include "mpi.h"
int main() #include <stdlib.h>
void insertionSort(int n, int* array)
{ {
int n, array[1000], c, d, t; int d,t,c;
printf("Enter number of elements\n");
scanf("%d", &n);
printf("Enter %d integers\n", n);
for (c = 0; c < n; c++) {
scanf("%d", &array[c]);
}
for (c = 1 ; c <= n - 1; c++) { for (c = 1 ; c <= n - 1; c++) {
d = c; d = c;
...@@ -27,12 +19,60 @@ int main() ...@@ -27,12 +19,60 @@ int main()
d--; d--;
} }
} }
}
int max(int *array, int size) {
int max = array[0];
int i;
for(i=1; i<size; i++) {
if(array[i]>max) max = array[i];
}
return max;
}
int min(int *array, int size) {
int min = array[0];
int i;
for(i=1; i<size; i++) {
if(array[i]<min) min = array[i];
}
return min;
}
int main() {
/*MPI_Init(NULL,NULL);
int rank;
int size;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
double time_bucket= 0.0;
double time_insert= 0.0;*/
int n, c, d, t;
printf("Enter number of elements\n");
scanf("%d", &n);
printf("Sorted list in ascending order:\n"); printf("Enter %d integers\n", n);
int *array = (int*)malloc(sizeof(int)*n);
for (c = 0; c < n; c++) {
scanf("%d", &array[c]);
}
//float div = (max(array, n) - min(array, n)/size);
//printf("%f", div);
insertionSort(n, array);
printf("Sorted list in ascending order:\n");
for (c = 0; c <= n - 1; c++) { for (c = 0; c <= n - 1; c++) {
printf("%d\n", array[c]); printf("%d\n", array[c]);
} }
return 0; }
}
\ No newline at end of file
#daftar host
localhost
167.205.35.26
167.205.35.28
167.205.35.29
167.205.35.30
167.205.35.31
sort 0 → 100755
File added
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment