From 4fa73b8423f7068d2b238807a86ebb47ea82194f Mon Sep 17 00:00:00 2001 From: AnupKumarPanwar <1anuppanwar@gmail.com> Date: Tue, 3 Oct 2017 16:29:46 +0530 Subject: [PATCH] Merged 2 folders for sorting algorithms --- Sorts/BubbleSort.c | 40 ----------------------------- Sorts/InsertionSort.c | 29 --------------------- Sorts/OtherBubbleSort.c | 56 ----------------------------------------- 3 files changed, 125 deletions(-) delete mode 100644 Sorts/BubbleSort.c delete mode 100644 Sorts/InsertionSort.c delete mode 100644 Sorts/OtherBubbleSort.c diff --git a/Sorts/BubbleSort.c b/Sorts/BubbleSort.c deleted file mode 100644 index 95e8453f..00000000 --- a/Sorts/BubbleSort.c +++ /dev/null @@ -1,40 +0,0 @@ -#include -#include - - -int main(){ - - int* ARRAY=NULL; - int ContinueFilling=1; //This is to know if we should continue filling our array - int ARRAY_LENGTH=0,isSorted=0,i,TEMPORARY_ELEMENT; - - //This code part is for filling our array - while(ContinueFilling){ - printf("Enter the value number %d \n",ARRAY_LENGTH+1); - ARRAY=(int *)realloc(ARRAY,sizeof(int)*(ARRAY_LENGTH)); - scanf("%d",&ARRAY[ARRAY_LENGTH]); - ARRAY_LENGTH+=1; - printf("would you enter an other value (1:Continue/0:Sort the actual array)?\n"); - scanf("%d",&ContinueFilling); - } - - //Then we sort it using Bubble Sort.. - - while(!isSorted){ //While our array's not sorted - isSorted=1; //we suppose that it's sorted - for(i=0;iARRAY[i+1]){ // if the two elements aren't sorted - isSorted=0; //it means that the array is not sorted - TEMPORARY_ELEMENT=ARRAY[i]; //and we switch these elements using TEMPORARY_ELEMENT - ARRAY[i]=ARRAY[i+1]; - ARRAY[i+1]=TEMPORARY_ELEMENT; - } - } - } - //And we display it - for(i=0;i -#incude -#define MAX 20 - - - -int main() -{ - int i, elmtToInsert , j , arraySort[MAX] = {0}; - - for(i = 1 ; i < MAX ; i++) - { - elmtToInsert = arraySort[i]; - j = i - 1 ; - - while( j >= 0 && elmtToInsert < arraySort[j]) - { - arraySort[j+1] = arraySort[j]; - j--; - } - - arraySort[j+1] = elmtToInsert ; - } - - - - - return EXIT_SUCCESS; -} diff --git a/Sorts/OtherBubbleSort.c b/Sorts/OtherBubbleSort.c deleted file mode 100644 index f11fd63e..00000000 --- a/Sorts/OtherBubbleSort.c +++ /dev/null @@ -1,56 +0,0 @@ -#include -#include -#define MAX 20 -#define TRUE 1 -#define FALSE 0 - - -int main() -{ - - int i , arraySort[MAX] ={0} , isSort = FALSE, changePlace; - - - /* For example - Insertion random values in array to test - */ - - - for(i = 0 ; i < MAX; i++) - { - arraySort[i] = rand()%101 ; - } - - -/* Algorithm of bubble methods */ - - while(isSort) - { - isSort = FALSE; - - for( i = 0 ; i < MAX - 1 ; i++) - { - if(arraySort[i] > arraySort[i+1]) - { - changePlace = arratSort[i]; - arraySort[i] = arraySort[i+1]; - arraySort[i+1] = changePlace ; - isSort = TRUE; - } - - } - } - - /* See if it works */ - - for(i = 0 ; i < MAX; i++) - { - printf("%d\n", arraySort[i]); - } - - - - - return EXIT_SUCCESS; - -}