From 51834df8fd2e202cb29bce6e879c8870bce0c9d8 Mon Sep 17 00:00:00 2001 From: Varun Joshi Date: Sat, 3 Oct 2020 23:43:19 +0530 Subject: [PATCH 1/4] added Prims algorithm and different versions of other algorithms in C language --- C/HeapSort/V3/main.c | 0 C/InsertionSort/v1/main.c | 59 ++++++++ C/InsertionSort/{ => v2}/InsertionSort.c | 0 C/Prims/Prims.c | 67 +++++++++ CONTRIBUTING.md | 1 + README-CN.md | 177 ++++++++++++----------- 6 files changed, 217 insertions(+), 87 deletions(-) create mode 100644 C/HeapSort/V3/main.c create mode 100644 C/InsertionSort/v1/main.c rename C/InsertionSort/{ => v2}/InsertionSort.c (100%) create mode 100644 C/Prims/Prims.c diff --git a/C/HeapSort/V3/main.c b/C/HeapSort/V3/main.c new file mode 100644 index 000000000..e69de29bb diff --git a/C/InsertionSort/v1/main.c b/C/InsertionSort/v1/main.c new file mode 100644 index 000000000..76617b2e6 --- /dev/null +++ b/C/InsertionSort/v1/main.c @@ -0,0 +1,59 @@ +#include +#include +#include +#define MAX 100000 + +int main() +{ + int a[MAX]; + int i,j,n; + clock_t s,e; + double t; + //size of elements + printf("enter the size\n"); + //input elements + scanf("%d",&n); + printf("enter the array elements\n"); + for(i=0;i=0&&a[j]>key) + { + a[j+1]=a[j]; + j=j-1; + } + a[j+1]=key; + } +} diff --git a/C/InsertionSort/InsertionSort.c b/C/InsertionSort/v2/InsertionSort.c similarity index 100% rename from C/InsertionSort/InsertionSort.c rename to C/InsertionSort/v2/InsertionSort.c diff --git a/C/Prims/Prims.c b/C/Prims/Prims.c new file mode 100644 index 000000000..a09975496 --- /dev/null +++ b/C/Prims/Prims.c @@ -0,0 +1,67 @@ +#include +#include +#define MAX 20 +#define INFINITY 999 +int cost[MAX][MAX],visited[MAX]; +void prims(int cost[][MAX],int n){ + + int i,j,ne=1; + int a,b,u,v,min,mincost=0; + for(i=0;i<=n;i++) + visited[i]=0; + printf("\n edges of the spanning tree"); + visited[1]=1; + while(ne Date: Sun, 11 Oct 2020 17:19:58 +0530 Subject: [PATCH 2/4] Delete InsertionSort.c --- C/InsertionSort/v2/InsertionSort.c | 56 ------------------------------ 1 file changed, 56 deletions(-) delete mode 100644 C/InsertionSort/v2/InsertionSort.c diff --git a/C/InsertionSort/v2/InsertionSort.c b/C/InsertionSort/v2/InsertionSort.c deleted file mode 100644 index 003680509..000000000 --- a/C/InsertionSort/v2/InsertionSort.c +++ /dev/null @@ -1,56 +0,0 @@ -// including liberary -#include - -/* - the algo goes here -*/ -void Sort_Array(int arr[], int size) // it will accept interger type array and size of the array -{ - // local variable defination - int i, key, j; - for (i = 1; i < size; i++) - { - key = arr[i]; // the i th value - j = i-1; // j is for processing from back - - /* Move elements of arr[0..i-1], that are - greater than key, to one position ahead - of their current position */ - while (j >= 0 && arr[j] > key) // loop will work till j th value of array is greater than i th value of array and j >= 0 - { - arr[j+1] = arr[j]; - j--; - } - arr[j+1] = key; - } -} - -/* - MAIN FUNCTION -*/ -int main() { - // declaring the variable - int size; // size is the array length - int i; // i is for iterations - printf("enter the size of array "); - scanf("%d",&size); // getting size - int array[size]; // declaring array of size entered by the user - - // getting value from the user - printf("\nenter values in the array\n"); - for (i = 0; i < size; i++) {scanf("%d", &array[i]); } - - // printing the original array - printf("\noriginal array -> "); - for (i = 0; i < size; i++) { printf("%d ", array[i]); } - - // sorting the array - Sort_Array(array, size); - - // printing the sorted array - printf("\nsorted array -> "); - for (i = 0; i < size; i++) { printf("%d ", array[i]); } - - return 0; -} - From cea0ffacafd31697cc7557b85c4b6a33aed5b0d1 Mon Sep 17 00:00:00 2001 From: Varun j <48326355+sixthcodebrewer@users.noreply.github.com> Date: Sun, 11 Oct 2020 17:20:11 +0530 Subject: [PATCH 3/4] Delete main.c --- C/HeapSort/V3/main.c | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 C/HeapSort/V3/main.c diff --git a/C/HeapSort/V3/main.c b/C/HeapSort/V3/main.c deleted file mode 100644 index e69de29bb..000000000 From 0e77d4eb4aa209be55f0e652ea49d789a50d86b6 Mon Sep 17 00:00:00 2001 From: Varun j <48326355+sixthcodebrewer@users.noreply.github.com> Date: Sun, 11 Oct 2020 17:20:51 +0530 Subject: [PATCH 4/4] deleted version --- C/InsertionSort/v1/main.c | 59 --------------------------------------- 1 file changed, 59 deletions(-) delete mode 100644 C/InsertionSort/v1/main.c diff --git a/C/InsertionSort/v1/main.c b/C/InsertionSort/v1/main.c deleted file mode 100644 index 76617b2e6..000000000 --- a/C/InsertionSort/v1/main.c +++ /dev/null @@ -1,59 +0,0 @@ -#include -#include -#include -#define MAX 100000 - -int main() -{ - int a[MAX]; - int i,j,n; - clock_t s,e; - double t; - //size of elements - printf("enter the size\n"); - //input elements - scanf("%d",&n); - printf("enter the array elements\n"); - for(i=0;i=0&&a[j]>key) - { - a[j+1]=a[j]; - j=j-1; - } - a[j+1]=key; - } -}