From 444d4b11d5fe89bd2e7f8d6f9594299cd858197a Mon Sep 17 00:00:00 2001 From: Anup Kumar Panwar <1anuppanwar@gmail.com> Date: Mon, 8 Oct 2018 21:18:35 +0530 Subject: [PATCH] Refactor --- .../Simpson's_1-3rd_rule.c | 34 -- .../statistic/README.md | 116 ----- .../statistic/src/statistic.c | 400 ------------------ .../statistic/src/statistic.h | 79 ---- .../statistic/test/test.c | 190 --------- Conversions/decimal _to_binary.c | 66 --- Sorts/HeapSort.c | 62 --- .../Gauss_Elimination.c | 0 .../MEAN.C | 0 .../MEDIAN.C | 0 .../Seidal.C | 0 .../lagrange_theorem.C | 0 .../simpson's 1-3rd rule.c | 0 .../variance.c | 0 .../{binary2hexa.c => binary_to_hexa.c} | 0 .../decimal_to_hexa.c | 0 .../decimal_to_octal.c | 0 {Conversions => conversions}/toDecimal.c | 0 .../Array/CArray.c | 0 .../Array/CArray.h | 0 .../Array/CArrayTests.c | 0 .../Array/README.md | 0 .../binary_trees/create_node.c | 0 .../binary_trees/recursive_traversals.c | 0 .../dictionary/README.md | 0 .../dictionary/dict.c | 0 .../dictionary/dict.h | 0 .../dictionary/test_program.c | 0 .../linked_list/mergeLinkedLists.c | 0 .../linked_list/singly_link_list_deletion.c | 0 .../linked_list/stack_using_linkedlists.c | 0 {Data Structures => data_structures}/queue.c | 0 {Data Structures => data_structures}/stack.c | 0 .../stack/README.md | 0 .../balanced parenthesis using stack in C | 0 .../stack/main.c | 0 .../stack/stack.c | 0 .../stack/stack.h | 0 .../trie/dictionary.txt | 0 .../trie/trie.c | 0 {Hash => hash}/README.md | 0 {Hash => hash}/hash.c | 0 {Hash => hash}/hash.h | 0 {Hash => hash}/test_program.c | 0 .../Problem 01/sol1.c | 0 .../Problem 01/sol2.c | 0 .../Problem 01/sol3.c | 0 .../Problem 02/so1.c | 0 .../Problem 03/sol1.c | 0 .../Problem 03/sol2.c | 0 {Project Euler => project_euler}/README.md | 0 {Searches => searching}/Binary_Search.c | 0 {Searches => searching}/Jump_Search.c | 0 {Searches => searching}/LinearSearch.c | 0 {Searches => searching}/Other_Binary_Search.c | 0 {Searches => searching}/fibonacciSearch.c | 0 .../interpolation_search.c | 0 .../modifiedBinarySearch.c | 0 {Sorts => sorting}/BogoSort.c | 0 {Sorts => sorting}/BubbleSort.c | 0 sorting/HeapSort.c | 118 +++--- {Sorts => sorting}/InsertionSort.c | 0 {Sorts => sorting}/OtherBubbleSort.c | 0 {Sorts => sorting}/QuickSort.c | 0 {Sorts => sorting}/SelectionSort.c | 0 {Sorts => sorting}/binary_insertion_sort.c | 0 {Sorts => sorting}/countingSort.c | 0 {Sorts => sorting}/mergesort.c | 0 {Sorts => sorting}/shaker_sort.c | 0 {Sorts => sorting}/shellSort.c | 0 70 files changed, 55 insertions(+), 1010 deletions(-) delete mode 100644 Computer Oriented Statistical Methods/Simpson's_1-3rd_rule.c delete mode 100644 Computer Oriented Statistical Methods/statistic/README.md delete mode 100644 Computer Oriented Statistical Methods/statistic/src/statistic.c delete mode 100644 Computer Oriented Statistical Methods/statistic/src/statistic.h delete mode 100644 Computer Oriented Statistical Methods/statistic/test/test.c delete mode 100644 Conversions/decimal _to_binary.c delete mode 100644 Sorts/HeapSort.c rename {computer-oriented-statistical-methods => computer_oriented_statistical_methods}/Gauss_Elimination.c (100%) rename {computer-oriented-statistical-methods => computer_oriented_statistical_methods}/MEAN.C (100%) rename {computer-oriented-statistical-methods => computer_oriented_statistical_methods}/MEDIAN.C (100%) rename {computer-oriented-statistical-methods => computer_oriented_statistical_methods}/Seidal.C (100%) rename {computer-oriented-statistical-methods => computer_oriented_statistical_methods}/lagrange_theorem.C (100%) rename {computer-oriented-statistical-methods => computer_oriented_statistical_methods}/simpson's 1-3rd rule.c (100%) rename {computer-oriented-statistical-methods => computer_oriented_statistical_methods}/variance.c (100%) rename conversions/{binary2hexa.c => binary_to_hexa.c} (100%) rename {Conversions => conversions}/decimal_to_hexa.c (100%) rename {Conversions => conversions}/decimal_to_octal.c (100%) rename {Conversions => conversions}/toDecimal.c (100%) rename {Data Structures => data_structures}/Array/CArray.c (100%) rename {Data Structures => data_structures}/Array/CArray.h (100%) rename {Data Structures => data_structures}/Array/CArrayTests.c (100%) rename {Data Structures => data_structures}/Array/README.md (100%) rename {Data Structures => data_structures}/binary_trees/create_node.c (100%) rename {Data Structures => data_structures}/binary_trees/recursive_traversals.c (100%) rename {Data Structures => data_structures}/dictionary/README.md (100%) rename {Data Structures => data_structures}/dictionary/dict.c (100%) rename {Data Structures => data_structures}/dictionary/dict.h (100%) rename {Data Structures => data_structures}/dictionary/test_program.c (100%) rename {Data Structures => data_structures}/linked_list/mergeLinkedLists.c (100%) rename {Data Structures => data_structures}/linked_list/singly_link_list_deletion.c (100%) rename {Data Structures => data_structures}/linked_list/stack_using_linkedlists.c (100%) rename {Data Structures => data_structures}/queue.c (100%) rename {Data Structures => data_structures}/stack.c (100%) rename {Data Structures => data_structures}/stack/README.md (100%) rename {Data Structures => data_structures}/stack/balanced parenthesis using stack in C (100%) rename {Data Structures => data_structures}/stack/main.c (100%) rename {Data Structures => data_structures}/stack/stack.c (100%) rename {Data Structures => data_structures}/stack/stack.h (100%) rename {Data Structures => data_structures}/trie/dictionary.txt (100%) rename {Data Structures => data_structures}/trie/trie.c (100%) rename {Hash => hash}/README.md (100%) rename {Hash => hash}/hash.c (100%) rename {Hash => hash}/hash.h (100%) rename {Hash => hash}/test_program.c (100%) rename {Project Euler => project_euler}/Problem 01/sol1.c (100%) rename {Project Euler => project_euler}/Problem 01/sol2.c (100%) rename {Project Euler => project_euler}/Problem 01/sol3.c (100%) rename {Project Euler => project_euler}/Problem 02/so1.c (100%) rename {Project Euler => project_euler}/Problem 03/sol1.c (100%) rename {Project Euler => project_euler}/Problem 03/sol2.c (100%) rename {Project Euler => project_euler}/README.md (100%) rename {Searches => searching}/Binary_Search.c (100%) rename {Searches => searching}/Jump_Search.c (100%) rename {Searches => searching}/LinearSearch.c (100%) rename {Searches => searching}/Other_Binary_Search.c (100%) rename {Searches => searching}/fibonacciSearch.c (100%) rename {Searches => searching}/interpolation_search.c (100%) rename {Searches => searching}/modifiedBinarySearch.c (100%) rename {Sorts => sorting}/BogoSort.c (100%) rename {Sorts => sorting}/BubbleSort.c (100%) rename {Sorts => sorting}/InsertionSort.c (100%) rename {Sorts => sorting}/OtherBubbleSort.c (100%) rename {Sorts => sorting}/QuickSort.c (100%) rename {Sorts => sorting}/SelectionSort.c (100%) rename {Sorts => sorting}/binary_insertion_sort.c (100%) rename {Sorts => sorting}/countingSort.c (100%) rename {Sorts => sorting}/mergesort.c (100%) rename {Sorts => sorting}/shaker_sort.c (100%) rename {Sorts => sorting}/shellSort.c (100%) diff --git a/Computer Oriented Statistical Methods/Simpson's_1-3rd_rule.c b/Computer Oriented Statistical Methods/Simpson's_1-3rd_rule.c deleted file mode 100644 index 3483b25c..00000000 --- a/Computer Oriented Statistical Methods/Simpson's_1-3rd_rule.c +++ /dev/null @@ -1,34 +0,0 @@ -#include -#include -#include -float f(float x) -{ - return 1.0+x*x*x; -} -void main() -{ - int i,n; - float a,b,h,x,s2,s3,sum,integral; - printf("enter the lower limit of the integration"); - sacnf("%f",&a); - printf("enter the upper limit of the integration"); - sacnf("%f",&b); - printf("enter the number of intervals"); - sacnf("%d",&n); - h=(b-a)/n; - sum=f(a)+f(b); - s2=s3=0.0; - for(i=1;i -#include -#include -#include - -#include "statistic.h" - -double average(int n, ...) -{ - va_list valist; - double sum = 0; - int i; - - /* initializes valist for num number of arguments */ - va_start(valist, n); - - /* adds up all double values of the sample. */ - for (i = 0; i < n; i++) - { - - sum += va_arg(valist, double); - } - - /* cleans memory reserved for valist */ - va_end(valist); - - return sum / n; -} - -double average_Array(int n, const double values[]) -{ - int i; - double sum = 0; - - /* adds up all double values of the sample. */ - for (i = 0; i < n; i++) - { - sum += values[i]; - } - - return sum / n; -} - -double standard_deviation(int n, ...) -{ - va_list valist; - double var = 0; - double avg = 0; - double value = 0; - double values[n]; - int i; - - /* initializes valist for num number of arguments */ - va_start(valist, n); - - for (i = 0; i < n; i++) - { - values[i] = va_arg(valist, double); - } - - va_end(valist); - va_start(valist, n); - - /* fetches the average */ - avg = average_Array(n, values); - - /* adds up all double values of the sample. */ - for (i = 0; i < n; i++) - { - value = va_arg(valist, double); - var += (value - avg) * (value - avg); - } - - var /= (double)(n - 1); - - /* cleans memory reserved for valist */ - va_end(valist); - - return sqrt(var); -} - -double standard_deviation_array(int n, const double values[]) -{ - - double var = 0; - double avg = 0; - int i; - - /* fetches the average */ - avg = average_Array(n, values); - - /* adds up all double values of the sample. */ - for (i = 0; i < n; i++) - { - var += (values[i] - avg) * (values[i] - avg); - } - - var /= (double)(n - 1); - - return sqrt(var); -} - -double standard_deviation_N(int n, ...) -{ - va_list valist; - double var = 0; - double avg = 0; - double value = 0; - double values[n]; - int i; - - /* initializes valist for num number of arguments */ - va_start(valist, n); - - for (i = 0; i < n; i++) - { - values[i] = va_arg(valist, double); - } - - va_end(valist); - va_start(valist, n); - - /* fetches the average */ - avg = average_Array(n, values); - - /* adds up all double values of the sample. */ - for (i = 0; i < n; i++) - { - value = va_arg(valist, double); - var += (value - avg) * (value - avg); - } - - var /= (double)n; - - /* cleans memory reserved for valist */ - va_end(valist); - - return sqrt(var); -} - -double standard_deviation_N_array(int n, const double values[]) -{ - double var = 0; - double avg = 0; - int i; - - /* fetches the average */ - avg = average_Array(n, values); - - /* adds up all double values of the sample. */ - for (i = 0; i < n; i++) - { - var += (values[i] - avg) * (values[i] - avg); - } - - var /= (double)n; - - return sqrt(var); -} - -double variance(int n, const double values[]) -{ - double var = 0; - double avg = 0; - int i; - - /* fetches the average */ - avg = average_Array(n, values); - - /* adds up all double values of the sample. */ - for (i = 0; i < n; i++) - { - var += (values[i] - avg) * (values[i] - avg); - } - - var /= (double)(n - 1); - - return var; -} - -double variance_N(int n, const double values[]) -{ - double var = 0; - double avg = 0; - int i; - - /* fetches the average */ - avg = average_Array(n, values); - - /* adds up all double values of the sample. */ - for (i = 0; i < n; i++) - { - var += (values[i] - avg) * (values[i] - avg); - } - - var /= (double)n; - - return var; -} - -double max(int n, const double values[]) -{ - double max = values[0]; - int i; - - /* iterates over all elements in 'values' */ - for (i = 1; i < n; i++) - { - if (values[i] > max) - { - max = values[i]; - } - } - - return max; -} - -double min(int n, const double values[]) -{ - double min = values[0]; - int i; - - /* iterates over all elements in 'values' */ - for (i = 1; i < n; i++) - { - if (values[i] < min) - { - min = values[i]; - } - } - - return min; -} - -/* - private helper-function for comparing two double values -*/ -int cmp(const void *a, const void *b) -{ - return (*(double *)a - *(double *)b); -} - -double median(int n, const double values[]) -{ - double tmp[n]; - int i; - - /* clones the array 'values' to array 'tmp' */ - for (i = 0; i < n; i++) - { - tmp[i] = values[i]; - } - - /* sorts the array 'tmp' with quicksort from stdlib.h */ - qsort(tmp, n, sizeof(double), cmp); - - if (n % 2 != 0) /* n is odd */ - { - /* integer division */ - return tmp[n / 2]; - } - else - { /* n is even */ - - /* uses the average(...) function, above. */ - return average(2, tmp[n / 2], tmp[(n / 2) - 1]); - } -} - -double sum(int n, const double values[]) -{ - double sum = 0; - int i; - - /* actual adding procedure */ - for (i = 0; i < n; i++) - { - sum += values[i]; - } - - return sum; -} - -double range(int n, const double values[]) -{ - return max(n, values) - min(n, values); -} - -double frequency_of(int n, const double values[], double val) -{ - int i; - double counter = 0; - - /* counts the number of occurs */ - for (i = 0; i < n; i++) - { - if (values[i] == val) - { - counter++; - } - } - - return counter / n; -} - -double quartile_I(int n, const double values[]) -{ - double sum = 0; - double freq = 0; - int i; - int d = 1; - double tmp[n]; - - for (i = 0; i < n; i++) - { - tmp[i] = values[i]; - } - - /* sorts the array 'tmp' with quicksort from stdlib.h */ - qsort(tmp, n, sizeof(double), cmp); - - double lastVal = tmp[0]; - - freq = frequency_of(n, values, lastVal); - sum += freq; - - for (i = 1; i < n; i++) - { - if (tmp[i] != lastVal) - { - freq = frequency_of(n, values, tmp[i]); - sum += freq; - lastVal = tmp[i]; - if (sum >= 0.25) - { - if (n % 2 != 0) - { - return values[i]; - } - else - { - - return average(2, values[i], values[i + 1]); - } - } - } - } -} - -double quartile_III(int n, const double values[]) -{ - double sum = 0; - double freq = 0; - int i; - double tmp[n]; - - for (i = 0; i < n; i++) - { - tmp[i] = values[i]; - } - - /* sorts the array 'tmp' with quicksort from stdlib.h */ - qsort(tmp, n, sizeof(double), cmp); - - double lastVal = tmp[0]; - - freq = frequency_of(n, values, lastVal); - sum += freq; - - for (i = 1; i < n; i++) - { - if (tmp[i] != lastVal) - { - freq = frequency_of(n, values, tmp[i]); - sum += freq; - lastVal = tmp[i]; - if (sum >= 0.75) - { - if (n % 2 != 0) - { - return values[i]; - } - else - { - return average(2, values[i], values[i + 1]); - } - } - } - } -} - -double quartile_distance(int n, const double values[]) -{ - return quartile_III(n, values) - quartile_I(n, values); -} \ No newline at end of file diff --git a/Computer Oriented Statistical Methods/statistic/src/statistic.h b/Computer Oriented Statistical Methods/statistic/src/statistic.h deleted file mode 100644 index bf7032bb..00000000 --- a/Computer Oriented Statistical Methods/statistic/src/statistic.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - author: Christian Bender - This file contains the public interface for the statistic-library. -*/ - -#ifndef __STATISTIC__H -#define __STATISTIC__H - -/* - Computes the average of a given sample. - The sample is a set of double values. - The average-function gets a variable number of arguments. The first argument - must be the number of arguments! - The averageArray-function instead gets a double-array of values and a int-number that - represents the size of the double-array. -*/ -double average_Array(int, const double[]); -double average(int, ...); - -/* - computes the standard deviation (n-1) -*/ -double standard_deviation(int, ...); -double standard_deviation_array(int, const double[]); - -/* - computes the standard deviation (n) -*/ -double standard_deviation_N(int, ...); -double standard_deviation_N_array(int, const double[]); - -/* - variance: computes the variance (n-1) - variance_N: computes the variance (n) -*/ - -double variance(int, const double[]); -double variance_N(int, const double[]); - -/* - gets the max (min) element of the sample -*/ -double max(int, const double[]); -double min(int, const double[]); - -/* - computes the median of the sample -*/ -double median(int, const double[]); - -/* - adds up all values of the sample. -*/ -double sum(int, const double[]); - -/* - computes the range of the sample. -*/ -double range(int, const double[]); - -/* - gets the frequency of the last argument (double) of that sample. -*/ -double frequency_of(int, const double[], double); - -/* - quartile_I: computes the first quartile. - quartile_III: computes the third quartile. - The second quartile is the median! -*/ -double quartile_I(int, const double[]); -double quartile_III(int, const double[]); - -/* - computes the quartile distance -*/ -double quartile_distance(int, const double[]); - -#endif \ No newline at end of file diff --git a/Computer Oriented Statistical Methods/statistic/test/test.c b/Computer Oriented Statistical Methods/statistic/test/test.c deleted file mode 100644 index 0396dc85..00000000 --- a/Computer Oriented Statistical Methods/statistic/test/test.c +++ /dev/null @@ -1,190 +0,0 @@ -/* - author: Christian Bender - This file contains a CUnit test suit for the statistic-library -*/ - -#include -#include -#include "CUnit/Basic.h" - -#include "../src/statistic.h" - -/* test for function average(...) */ -void test_average(void) -{ - CU_ASSERT_DOUBLE_EQUAL(average(3,1.0,2.5,3.5),2.333,0.01); -} - -/* test for function averageArray(...) */ -void test_average_Array(void) -{ - double values[] = {1.0, 2.5, 3.5}; - CU_ASSERT_DOUBLE_EQUAL(average_Array(3, values), 2.333, 0.01); -} - -/* test for function standard_deviation(...) */ -void test_standard_deviation(void) -{ - CU_ASSERT_DOUBLE_EQUAL(standard_deviation(4, 15.0, 70.0, 25.0, 50.0), 24.8328, 0.01); -} - -/* test for function standard_deviation_array() */ -void test_standard_deviation_array(void) -{ - double values[] = {15.0, 70.0, 25.0, 50.0}; - CU_ASSERT_DOUBLE_EQUAL(standard_deviation_array(4, values), 24.8328, 0.01); -} - -/* test for function standard_deviation_N(...) */ -void test_standard_deviation_N(void) -{ - CU_ASSERT_DOUBLE_EQUAL(standard_deviation_N(4, 15.0, 70.0, 25.0, 50.0), 21.5058, 0.01); -} - -/* test for function standard_deviation_N_array() */ -void test_standard_deviation_N_array(void) -{ - double values[] = {15.0, 70.0, 25.0, 50.0}; - CU_ASSERT_DOUBLE_EQUAL(standard_deviation_N_array(4, values), 21.5058, 0.01); -} - -/* test for the function variance(...) */ -void test_variance(void) -{ - double values[] = {15.0, 70.0, 25.0, 50.0}; - CU_ASSERT_DOUBLE_EQUAL(variance(4, values), 616.6667, 0.01); -} - -/* test for the function variance(...) */ -void test_variance_N(void) -{ - double values[] = {15.0, 70.0, 25.0, 50.0}; - CU_ASSERT_DOUBLE_EQUAL(variance_N(4, values), 462.5, 0.01); -} - -/* test for the max(...) function */ -void test_max(void) -{ - double values[] = {15.0, 70.0, 25.0, 50.0}; - CU_ASSERT_DOUBLE_EQUAL(max(4, values), 70.0, 0.01); -} - -/* test for the min(...) function */ -void test_min(void) -{ - double values[] = {15.0, 70.0, 25.0, 50.0}; - CU_ASSERT_DOUBLE_EQUAL(min(4, values), 15.0, 0.01); -} - -/* test for the median(...)-function */ -void test_median(void) -{ - double values[] = {15.0, 70.0, 25.0, 50.0}; - CU_ASSERT_DOUBLE_EQUAL(median(4, values), 37.5, 0.01); -} - - -/* test for the sum(...)-function */ -void test_sum(void) -{ - double values[] = {15.0, 70.0, 25.0, 50.0}; - CU_ASSERT_DOUBLE_EQUAL(sum(4, values), 160, 0.01); -} - - -/* test for the range(...)-function */ -void test_range(void) -{ - double values[] = {15.0, 70.0, 25.0, 50.0}; - CU_ASSERT_DOUBLE_EQUAL(range(4, values), 55, 0.01); -} - - -/* test of frequency_of(...)-function */ -void test_frequency_of(void) -{ - double values[] = {1.0,7.0,2.5,2.5,6.0}; - CU_ASSERT_DOUBLE_EQUAL(frequency_of(5, values,2.5), 0.4, 0.01); - CU_ASSERT_DOUBLE_EQUAL(frequency_of(5, values,6.0), 0.2, 0.01); -} - - -/* test of quartile_I(...) and quartile_III(...)-function */ -void test_quartile(void) -{ - double values[] = {3.0,4.0,5.0,7.0,7.0,7.0,8.0,9.0,11.0,13.0,13.0,13.0,15.0,16.0}; - double sample[] = {1600.0,2300.0,2300.0,2400.0,2900.0,3200,3500,4500,4600,5200,6500,12000}; - CU_ASSERT_DOUBLE_EQUAL(quartile_I(14, values), 7.0, 0.01); - CU_ASSERT_DOUBLE_EQUAL(quartile_III(14, values), 13.0, 0.01); - CU_ASSERT_DOUBLE_EQUAL(quartile_III(12, sample), 4900.0, 0.01); -} - - -/* test for quartile_distance(...)-function */ -void test_quartile_distance(void) -{ - double values[] = {3.0,4.0,5.0,7.0,7.0,7.0,8.0,9.0,11.0,13.0,13.0,13.0,15.0,16.0}; - CU_ASSERT_DOUBLE_EQUAL(quartile_distance(14, values), 6.0, 0.01); -} - -/* - init suite -*/ -int init_suite1(void) -{ - return 0; -} - -/* - clean suite -*/ -int clean_suite1(void) -{ - return 0; -} - -/* test runner */ -int main(void) -{ - CU_pSuite pSuite = NULL; - - /* initializes CUnit */ - if (CUE_SUCCESS != CU_initialize_registry()) - return CU_get_error(); - - /* adds the suit "Test for statistic" to the registry */ - pSuite = CU_add_suite("Test for statistic", init_suite1, clean_suite1); - if (NULL == pSuite) - { - CU_cleanup_registry(); - return CU_get_error(); - } - - /* registers the individual tests to the test-suite */ - if ((NULL == CU_add_test(pSuite, "test of average()", test_average)) - || (NULL == CU_add_test(pSuite, "test of average_Array()", test_average_Array)) - || (NULL == CU_add_test(pSuite, "test of standard_deviation()", test_standard_deviation)) - || (NULL == CU_add_test(pSuite, "test of standard_deviation_array()", test_standard_deviation_array)) - || (NULL == CU_add_test(pSuite, "test of standard_deviation_N_array()", test_standard_deviation_N_array)) - || (NULL == CU_add_test(pSuite, "test of standard_deviation_N()", test_standard_deviation_N)) - || (NULL == CU_add_test(pSuite, "test of variance()", test_variance)) - || (NULL == CU_add_test(pSuite, "test of variance_N()", test_variance_N)) - || (NULL == CU_add_test(pSuite, "test of max()", test_max)) - || (NULL == CU_add_test(pSuite, "test of min()", test_min)) - || (NULL == CU_add_test(pSuite, "test of median()", test_median)) - || (NULL == CU_add_test(pSuite, "test of sum()", test_sum)) - || (NULL == CU_add_test(pSuite, "test of range()", test_range)) - || (NULL == CU_add_test(pSuite, "test of frequency_of()", test_frequency_of)) - || (NULL == CU_add_test(pSuite, "test of quartile_I() and quartile_III()", test_quartile)) - || (NULL == CU_add_test(pSuite, "test of quartile_distance()", test_quartile_distance))) - { - CU_cleanup_registry(); - return CU_get_error(); - } - - /* runs tests */ - CU_basic_set_mode(CU_BRM_VERBOSE); - CU_basic_run_tests(); - CU_cleanup_registry(); - return CU_get_error(); -} \ No newline at end of file diff --git a/Conversions/decimal _to_binary.c b/Conversions/decimal _to_binary.c deleted file mode 100644 index e27d18f7..00000000 --- a/Conversions/decimal _to_binary.c +++ /dev/null @@ -1,66 +0,0 @@ -#include -#include - -#define MAXBITS 100 - -int main() -{ - - // input of the user - int inputNumber; - - // for the remainder - int re; - - // contains the bits 0/1 - int bits[MAXBITS]; - - // for the loops - int j; - int i=0; - - printf("\t\tConverter decimal --> binary\n\n"); - - // reads a decimal number from the user. - printf("\nenter a positive integer number: "); - scanf("%d",&inputNumber); - - // make sure the input number is a positive integer. - if (inputNumber < 0) - { - printf("only positive integers >= 0\n"); - return 1; - } - - // actual processing - while(inputNumber>0) - { - - // computes the remainder by modulo 2 - re = inputNumber % 2; - - // computes the quotient of division by 2 - inputNumber = inputNumber / 2; - - bits[i] = re; - i++; - - } - - printf("\n the number in binary is: "); - - // iterates backwards over all bits - for(j=i-1; j>=0; j--) - { - printf("%d",bits[j]); - } - - // for the case the input number is 0 - if (i == 0) - { - printf("0"); - } - - return 0; -} - diff --git a/Sorts/HeapSort.c b/Sorts/HeapSort.c deleted file mode 100644 index 0010091a..00000000 --- a/Sorts/HeapSort.c +++ /dev/null @@ -1,62 +0,0 @@ -#include - -void heapify(int *unsorted, int index, int heap_size); -void heap_sort(int *unsorted, int n); - -int main() { - int n = 0; - int i = 0; - char oper; - - int* unsorted; - printf("Enter the size of the array you want\n"); - scanf("%d", &n); - unsorted = (int*)malloc(sizeof(int) * n); - while (getchar() != '\n'); - printf("Enter numbers separated by a comma:\n"); - while (i != n) { - scanf("%d,", (unsorted + i)); - i++; - } - heap_sort(unsorted, n); - - printf("["); - printf("%d", *(unsorted)); - for (int i = 1; i < n; i++) { - printf(", %d", *(unsorted + i)); - } - printf("]"); -} - -void heapify(int *unsorted, int index, int heap_size) { - int temp; - int largest = index; - int left_index = 2 * index; - int right_index = 2 * index + 1; - if (left_index < heap_size && *(unsorted + left_index) > *(unsorted + largest)) { - largest = left_index; - } - if (right_index < heap_size && *(unsorted + right_index) > *(unsorted + largest)) { - largest = right_index; - } - - if (largest != index) { - temp = *(unsorted + largest); - *(unsorted + largest) = *(unsorted + index); - *(unsorted + index) = temp; - heapify(unsorted, largest, heap_size); - } -} - -void heap_sort(int *unsorted, int n) { - int temp; - for (int i = n / 2 - 1; i > -1; i--) { - heapify(unsorted, i, n); - } - for (int i = n - 1; i > 0; i--) { - temp = *(unsorted); - *(unsorted) = *(unsorted + i); - *(unsorted + i) = temp; - heapify(unsorted, 0, i); - } -} diff --git a/computer-oriented-statistical-methods/Gauss_Elimination.c b/computer_oriented_statistical_methods/Gauss_Elimination.c similarity index 100% rename from computer-oriented-statistical-methods/Gauss_Elimination.c rename to computer_oriented_statistical_methods/Gauss_Elimination.c diff --git a/computer-oriented-statistical-methods/MEAN.C b/computer_oriented_statistical_methods/MEAN.C similarity index 100% rename from computer-oriented-statistical-methods/MEAN.C rename to computer_oriented_statistical_methods/MEAN.C diff --git a/computer-oriented-statistical-methods/MEDIAN.C b/computer_oriented_statistical_methods/MEDIAN.C similarity index 100% rename from computer-oriented-statistical-methods/MEDIAN.C rename to computer_oriented_statistical_methods/MEDIAN.C diff --git a/computer-oriented-statistical-methods/Seidal.C b/computer_oriented_statistical_methods/Seidal.C similarity index 100% rename from computer-oriented-statistical-methods/Seidal.C rename to computer_oriented_statistical_methods/Seidal.C diff --git a/computer-oriented-statistical-methods/lagrange_theorem.C b/computer_oriented_statistical_methods/lagrange_theorem.C similarity index 100% rename from computer-oriented-statistical-methods/lagrange_theorem.C rename to computer_oriented_statistical_methods/lagrange_theorem.C diff --git a/computer-oriented-statistical-methods/simpson's 1-3rd rule.c b/computer_oriented_statistical_methods/simpson's 1-3rd rule.c similarity index 100% rename from computer-oriented-statistical-methods/simpson's 1-3rd rule.c rename to computer_oriented_statistical_methods/simpson's 1-3rd rule.c diff --git a/computer-oriented-statistical-methods/variance.c b/computer_oriented_statistical_methods/variance.c similarity index 100% rename from computer-oriented-statistical-methods/variance.c rename to computer_oriented_statistical_methods/variance.c diff --git a/conversions/binary2hexa.c b/conversions/binary_to_hexa.c similarity index 100% rename from conversions/binary2hexa.c rename to conversions/binary_to_hexa.c diff --git a/Conversions/decimal_to_hexa.c b/conversions/decimal_to_hexa.c similarity index 100% rename from Conversions/decimal_to_hexa.c rename to conversions/decimal_to_hexa.c diff --git a/Conversions/decimal_to_octal.c b/conversions/decimal_to_octal.c similarity index 100% rename from Conversions/decimal_to_octal.c rename to conversions/decimal_to_octal.c diff --git a/Conversions/toDecimal.c b/conversions/toDecimal.c similarity index 100% rename from Conversions/toDecimal.c rename to conversions/toDecimal.c diff --git a/Data Structures/Array/CArray.c b/data_structures/Array/CArray.c similarity index 100% rename from Data Structures/Array/CArray.c rename to data_structures/Array/CArray.c diff --git a/Data Structures/Array/CArray.h b/data_structures/Array/CArray.h similarity index 100% rename from Data Structures/Array/CArray.h rename to data_structures/Array/CArray.h diff --git a/Data Structures/Array/CArrayTests.c b/data_structures/Array/CArrayTests.c similarity index 100% rename from Data Structures/Array/CArrayTests.c rename to data_structures/Array/CArrayTests.c diff --git a/Data Structures/Array/README.md b/data_structures/Array/README.md similarity index 100% rename from Data Structures/Array/README.md rename to data_structures/Array/README.md diff --git a/Data Structures/binary_trees/create_node.c b/data_structures/binary_trees/create_node.c similarity index 100% rename from Data Structures/binary_trees/create_node.c rename to data_structures/binary_trees/create_node.c diff --git a/Data Structures/binary_trees/recursive_traversals.c b/data_structures/binary_trees/recursive_traversals.c similarity index 100% rename from Data Structures/binary_trees/recursive_traversals.c rename to data_structures/binary_trees/recursive_traversals.c diff --git a/Data Structures/dictionary/README.md b/data_structures/dictionary/README.md similarity index 100% rename from Data Structures/dictionary/README.md rename to data_structures/dictionary/README.md diff --git a/Data Structures/dictionary/dict.c b/data_structures/dictionary/dict.c similarity index 100% rename from Data Structures/dictionary/dict.c rename to data_structures/dictionary/dict.c diff --git a/Data Structures/dictionary/dict.h b/data_structures/dictionary/dict.h similarity index 100% rename from Data Structures/dictionary/dict.h rename to data_structures/dictionary/dict.h diff --git a/Data Structures/dictionary/test_program.c b/data_structures/dictionary/test_program.c similarity index 100% rename from Data Structures/dictionary/test_program.c rename to data_structures/dictionary/test_program.c diff --git a/Data Structures/linked_list/mergeLinkedLists.c b/data_structures/linked_list/mergeLinkedLists.c similarity index 100% rename from Data Structures/linked_list/mergeLinkedLists.c rename to data_structures/linked_list/mergeLinkedLists.c diff --git a/Data Structures/linked_list/singly_link_list_deletion.c b/data_structures/linked_list/singly_link_list_deletion.c similarity index 100% rename from Data Structures/linked_list/singly_link_list_deletion.c rename to data_structures/linked_list/singly_link_list_deletion.c diff --git a/Data Structures/linked_list/stack_using_linkedlists.c b/data_structures/linked_list/stack_using_linkedlists.c similarity index 100% rename from Data Structures/linked_list/stack_using_linkedlists.c rename to data_structures/linked_list/stack_using_linkedlists.c diff --git a/Data Structures/queue.c b/data_structures/queue.c similarity index 100% rename from Data Structures/queue.c rename to data_structures/queue.c diff --git a/Data Structures/stack.c b/data_structures/stack.c similarity index 100% rename from Data Structures/stack.c rename to data_structures/stack.c diff --git a/Data Structures/stack/README.md b/data_structures/stack/README.md similarity index 100% rename from Data Structures/stack/README.md rename to data_structures/stack/README.md diff --git a/Data Structures/stack/balanced parenthesis using stack in C b/data_structures/stack/balanced parenthesis using stack in C similarity index 100% rename from Data Structures/stack/balanced parenthesis using stack in C rename to data_structures/stack/balanced parenthesis using stack in C diff --git a/Data Structures/stack/main.c b/data_structures/stack/main.c similarity index 100% rename from Data Structures/stack/main.c rename to data_structures/stack/main.c diff --git a/Data Structures/stack/stack.c b/data_structures/stack/stack.c similarity index 100% rename from Data Structures/stack/stack.c rename to data_structures/stack/stack.c diff --git a/Data Structures/stack/stack.h b/data_structures/stack/stack.h similarity index 100% rename from Data Structures/stack/stack.h rename to data_structures/stack/stack.h diff --git a/Data Structures/trie/dictionary.txt b/data_structures/trie/dictionary.txt similarity index 100% rename from Data Structures/trie/dictionary.txt rename to data_structures/trie/dictionary.txt diff --git a/Data Structures/trie/trie.c b/data_structures/trie/trie.c similarity index 100% rename from Data Structures/trie/trie.c rename to data_structures/trie/trie.c diff --git a/Hash/README.md b/hash/README.md similarity index 100% rename from Hash/README.md rename to hash/README.md diff --git a/Hash/hash.c b/hash/hash.c similarity index 100% rename from Hash/hash.c rename to hash/hash.c diff --git a/Hash/hash.h b/hash/hash.h similarity index 100% rename from Hash/hash.h rename to hash/hash.h diff --git a/Hash/test_program.c b/hash/test_program.c similarity index 100% rename from Hash/test_program.c rename to hash/test_program.c diff --git a/Project Euler/Problem 01/sol1.c b/project_euler/Problem 01/sol1.c similarity index 100% rename from Project Euler/Problem 01/sol1.c rename to project_euler/Problem 01/sol1.c diff --git a/Project Euler/Problem 01/sol2.c b/project_euler/Problem 01/sol2.c similarity index 100% rename from Project Euler/Problem 01/sol2.c rename to project_euler/Problem 01/sol2.c diff --git a/Project Euler/Problem 01/sol3.c b/project_euler/Problem 01/sol3.c similarity index 100% rename from Project Euler/Problem 01/sol3.c rename to project_euler/Problem 01/sol3.c diff --git a/Project Euler/Problem 02/so1.c b/project_euler/Problem 02/so1.c similarity index 100% rename from Project Euler/Problem 02/so1.c rename to project_euler/Problem 02/so1.c diff --git a/Project Euler/Problem 03/sol1.c b/project_euler/Problem 03/sol1.c similarity index 100% rename from Project Euler/Problem 03/sol1.c rename to project_euler/Problem 03/sol1.c diff --git a/Project Euler/Problem 03/sol2.c b/project_euler/Problem 03/sol2.c similarity index 100% rename from Project Euler/Problem 03/sol2.c rename to project_euler/Problem 03/sol2.c diff --git a/Project Euler/README.md b/project_euler/README.md similarity index 100% rename from Project Euler/README.md rename to project_euler/README.md diff --git a/Searches/Binary_Search.c b/searching/Binary_Search.c similarity index 100% rename from Searches/Binary_Search.c rename to searching/Binary_Search.c diff --git a/Searches/Jump_Search.c b/searching/Jump_Search.c similarity index 100% rename from Searches/Jump_Search.c rename to searching/Jump_Search.c diff --git a/Searches/LinearSearch.c b/searching/LinearSearch.c similarity index 100% rename from Searches/LinearSearch.c rename to searching/LinearSearch.c diff --git a/Searches/Other_Binary_Search.c b/searching/Other_Binary_Search.c similarity index 100% rename from Searches/Other_Binary_Search.c rename to searching/Other_Binary_Search.c diff --git a/Searches/fibonacciSearch.c b/searching/fibonacciSearch.c similarity index 100% rename from Searches/fibonacciSearch.c rename to searching/fibonacciSearch.c diff --git a/Searches/interpolation_search.c b/searching/interpolation_search.c similarity index 100% rename from Searches/interpolation_search.c rename to searching/interpolation_search.c diff --git a/Searches/modifiedBinarySearch.c b/searching/modifiedBinarySearch.c similarity index 100% rename from Searches/modifiedBinarySearch.c rename to searching/modifiedBinarySearch.c diff --git a/Sorts/BogoSort.c b/sorting/BogoSort.c similarity index 100% rename from Sorts/BogoSort.c rename to sorting/BogoSort.c diff --git a/Sorts/BubbleSort.c b/sorting/BubbleSort.c similarity index 100% rename from Sorts/BubbleSort.c rename to sorting/BubbleSort.c diff --git a/sorting/HeapSort.c b/sorting/HeapSort.c index e3a9f31b..0010091a 100644 --- a/sorting/HeapSort.c +++ b/sorting/HeapSort.c @@ -1,70 +1,62 @@ -// Heap sort #include -void printArr(int *A, int size) -{ - for (int i = 0; i < size; i++) - { - printf("%d ", A[i]); - } - printf("\n"); +void heapify(int *unsorted, int index, int heap_size); +void heap_sort(int *unsorted, int n); + +int main() { + int n = 0; + int i = 0; + char oper; + + int* unsorted; + printf("Enter the size of the array you want\n"); + scanf("%d", &n); + unsorted = (int*)malloc(sizeof(int) * n); + while (getchar() != '\n'); + printf("Enter numbers separated by a comma:\n"); + while (i != n) { + scanf("%d,", (unsorted + i)); + i++; + } + heap_sort(unsorted, n); + + printf("["); + printf("%d", *(unsorted)); + for (int i = 1; i < n; i++) { + printf(", %d", *(unsorted + i)); + } + printf("]"); } -void swap(int *a, int *b) -{ - int temp = *a; - *a = *b; - *b = temp; +void heapify(int *unsorted, int index, int heap_size) { + int temp; + int largest = index; + int left_index = 2 * index; + int right_index = 2 * index + 1; + if (left_index < heap_size && *(unsorted + left_index) > *(unsorted + largest)) { + largest = left_index; + } + if (right_index < heap_size && *(unsorted + right_index) > *(unsorted + largest)) { + largest = right_index; + } + + if (largest != index) { + temp = *(unsorted + largest); + *(unsorted + largest) = *(unsorted + index); + *(unsorted + index) = temp; + heapify(unsorted, largest, heap_size); + } } -// heap looks like -// 9 1 2 8 3 4 7 5 -// 9 8 4 7 -// 9 7 -// 9 -// the array is heap mean arr[i]>max(arr[i*2+1],arr[i*2+2]) -// the arr[0] is max of the array -void heapShift(int *arr, int index, int size) -{ - // put arr[index] to arr[index+1..size-1] follow heap - int i = index; - int j = 2 * i + 1; - while (j < size) - { - if (j != size - 1) // there exist j and j+1 - { - if (arr[j + 1] > arr[j]) // find max of arr[j] and arr[j+1] - j++; - } - if (arr[i] > arr[j]) // already heap - break; - swap(&arr[i], &arr[j]); - // move i, j - i = j; - j = i * 2 + 1; - } -} - -void heapSort(int *arr, int size) -{ - // the array is split to to half - // just care the first half to put heap - for (int i = size / 2; i >= 0; i--) - { - heapShift(arr, i, size); - } - for (int i = size - 1; i >= 0; i--) - { - swap(&arr[0], &arr[i]); // move max of array to the end - heapShift(arr, 0, i); // find max of arr[0..i-1], move to arr[0] - } -} - -int main() -{ - int A[] = {9, 8, 7, 6, 5, 4, 3, 2, 1}; - int size = sizeof(A) / sizeof(A[0]); - heapSort(A, size); - printArr(A, size); - return 0; +void heap_sort(int *unsorted, int n) { + int temp; + for (int i = n / 2 - 1; i > -1; i--) { + heapify(unsorted, i, n); + } + for (int i = n - 1; i > 0; i--) { + temp = *(unsorted); + *(unsorted) = *(unsorted + i); + *(unsorted + i) = temp; + heapify(unsorted, 0, i); + } } diff --git a/Sorts/InsertionSort.c b/sorting/InsertionSort.c similarity index 100% rename from Sorts/InsertionSort.c rename to sorting/InsertionSort.c diff --git a/Sorts/OtherBubbleSort.c b/sorting/OtherBubbleSort.c similarity index 100% rename from Sorts/OtherBubbleSort.c rename to sorting/OtherBubbleSort.c diff --git a/Sorts/QuickSort.c b/sorting/QuickSort.c similarity index 100% rename from Sorts/QuickSort.c rename to sorting/QuickSort.c diff --git a/Sorts/SelectionSort.c b/sorting/SelectionSort.c similarity index 100% rename from Sorts/SelectionSort.c rename to sorting/SelectionSort.c diff --git a/Sorts/binary_insertion_sort.c b/sorting/binary_insertion_sort.c similarity index 100% rename from Sorts/binary_insertion_sort.c rename to sorting/binary_insertion_sort.c diff --git a/Sorts/countingSort.c b/sorting/countingSort.c similarity index 100% rename from Sorts/countingSort.c rename to sorting/countingSort.c diff --git a/Sorts/mergesort.c b/sorting/mergesort.c similarity index 100% rename from Sorts/mergesort.c rename to sorting/mergesort.c diff --git a/Sorts/shaker_sort.c b/sorting/shaker_sort.c similarity index 100% rename from Sorts/shaker_sort.c rename to sorting/shaker_sort.c diff --git a/Sorts/shellSort.c b/sorting/shellSort.c similarity index 100% rename from Sorts/shellSort.c rename to sorting/shellSort.c