rename to counting sort

This commit is contained in:
Chris Cromer 2018-11-20 12:16:29 -03:00
parent 1094451880
commit 02ea6050e9
Signed by: cromer
GPG Key ID: 39CC813FF3C8708A
6 changed files with 18 additions and 18 deletions

View File

@ -1,7 +1,7 @@
CC=gcc CC=gcc
CFLAGS=-Wall -Isrc/include -DDEBUG -g CFLAGS=-Wall -Isrc/include -DDEBUG -g
LDFLAGS=-lm LDFLAGS=-lm
SRC=src/sort.c src/random.c src/bubble_sort.c src/timer.c src/count_sort.c src/quick_sort.c src/merge_sort.c src/bitonic_sort.c src/selection_sort.c SRC=src/sort.c src/random.c src/bubble_sort.c src/timer.c src/counting_sort.c src/quick_sort.c src/merge_sort.c src/bitonic_sort.c src/selection_sort.c
OBJ=$(SRC:.c=.o) OBJ=$(SRC:.c=.o)
all: sort informe all: sort informe

View File

@ -22,7 +22,7 @@
* @param array El array a ordenar * @param array El array a ordenar
* @param n El tamaño del array * @param n El tamaño del array
*/ */
void count_sort(int *array, int n) { void counting_sort(int *array, int n) {
int i; int i;
int j; int j;
int *temp = malloc(sizeof(int) * n); int *temp = malloc(sizeof(int) * n);

View File

@ -13,7 +13,7 @@
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef _SORT_COUNT #ifndef _SORT_COUNTING
#define _SORT_COUNT #define _SORT_COUNTING
void count_sort(int *array, int n); void counting_sort(int *array, int n);
#endif #endif

View File

@ -22,7 +22,7 @@
#include "random.h" #include "random.h"
#include "timer.h" #include "timer.h"
#include "bubble_sort.h" #include "bubble_sort.h"
#include "count_sort.h" #include "counting_sort.h"
#include "quick_sort.h" #include "quick_sort.h"
#include "bitonic_sort.h" #include "bitonic_sort.h"
#include "selection_sort.h" #include "selection_sort.h"
@ -49,7 +49,7 @@ void print_usage() {
fprintf(stdout, " -q, --quick usar quick sort\n"); fprintf(stdout, " -q, --quick usar quick sort\n");
fprintf(stdout, " -b, --bubble usar bubble sort\n"); fprintf(stdout, " -b, --bubble usar bubble sort\n");
fprintf(stdout, " -B, --bitonic usar bitonic sort\n"); fprintf(stdout, " -B, --bitonic usar bitonic sort\n");
fprintf(stdout, " -c, --count usar ordenamiento por conteo\n"); fprintf(stdout, " -c, --counting usar ordenamiento por conteo\n");
fprintf(stdout, " -s, --selection usar ordenamiento por selección\n"); fprintf(stdout, " -s, --selection usar ordenamiento por selección\n");
fprintf(stdout, " -n, --n=N la cantidad de elementos a ordenar, la\n"); fprintf(stdout, " -n, --n=N la cantidad de elementos a ordenar, la\n");
fprintf(stdout, " cantidad predeterminado es 10\n"); fprintf(stdout, " cantidad predeterminado es 10\n");
@ -183,7 +183,7 @@ int main (int argc, char **argv) {
int quick = 0; int quick = 0;
int bubble = 0; int bubble = 0;
int bitonic = 0; int bitonic = 0;
int count = 0; int counting = 0;
int selection = 0; int selection = 0;
int opt; int opt;
int long_index = 0; int long_index = 0;
@ -193,7 +193,7 @@ int main (int argc, char **argv) {
{"quick", no_argument, 0, 'q'}, {"quick", no_argument, 0, 'q'},
{"bubble", no_argument, 0, 'b'}, {"bubble", no_argument, 0, 'b'},
{"bitonic", no_argument, 0, 'B'}, {"bitonic", no_argument, 0, 'B'},
{"count", no_argument, 0, 'c'}, {"counting", no_argument, 0, 'c'},
{"selection", no_argument, 0, 's'}, {"selection", no_argument, 0, 's'},
{"n", required_argument, 0, 'n'}, {"n", required_argument, 0, 'n'},
{"elegir", no_argument, 0, 'e'}, {"elegir", no_argument, 0, 'e'},
@ -215,7 +215,7 @@ int main (int argc, char **argv) {
quick = 1; quick = 1;
bubble = 1; bubble = 1;
bitonic = 1; bitonic = 1;
count = 1; counting = 1;
selection = 1; selection = 1;
break; break;
case 'm': case 'm':
@ -231,7 +231,7 @@ int main (int argc, char **argv) {
bitonic = 1; bitonic = 1;
break; break;
case 'c': case 'c':
count = 1; counting = 1;
break; break;
case 's': case 's':
selection = 1; selection = 1;
@ -296,7 +296,7 @@ int main (int argc, char **argv) {
} }
} }
if (!merge && !quick && !bubble && !bitonic && !count && !selection) { if (!merge && !quick && !bubble && !bitonic && !counting && !selection) {
fprintf(stderr, "Error: No se seleccionó un algoritmo valido!\n"); fprintf(stderr, "Error: No se seleccionó un algoritmo valido!\n");
print_usage(); print_usage();
return 4; return 4;
@ -351,8 +351,8 @@ int main (int argc, char **argv) {
end_sort(); end_sort();
} }
// O(n^2) // O((1/2) * n^2 - (1/2) * n)
if (count) { if (counting) {
start_sort("Count sort corriendo... ", n); start_sort("Count sort corriendo... ", n);
count_sort(work_array, n); count_sort(work_array, n);
end_sort(); end_sort();

View File

@ -3,7 +3,7 @@ CFLAGS=-Wall -I../src/include -DDEBUG -g
SRC=test.c SRC=test.c
OBJ=$(SRC:.c=.o) OBJ=$(SRC:.c=.o)
OBJ+=../src/random.o ../src/bubble_sort.o ../src/count_sort.o ../src/quick_sort.o ../src/merge_sort.o ../src/bitonic_sort.o ../src/selection_sort.o OBJ+=../src/random.o ../src/bubble_sort.o ../src/counting_sort.o ../src/quick_sort.o ../src/merge_sort.o ../src/bitonic_sort.o ../src/selection_sort.o
all: test all: test

View File

@ -19,7 +19,7 @@
#include <unistd.h> #include <unistd.h>
#include "random.h" #include "random.h"
#include "bubble_sort.h" #include "bubble_sort.h"
#include "count_sort.h" #include "counting_sort.h"
#include "selection_sort.h" #include "selection_sort.h"
#include "bitonic_sort.h" #include "bitonic_sort.h"
#include "merge_sort.h" #include "merge_sort.h"
@ -124,10 +124,10 @@ int main(int argc, char **argv) {
passed++; passed++;
} }
// Test count sort // Test counting sort
pass = 1; pass = 1;
memcpy(test_array, test_case, sizeof(int) * n); memcpy(test_array, test_case, sizeof(int) * n);
fprintf(stdout, "\tcount sort: "); fprintf(stdout, "\tcounting sort: ");
fflush(stdout); fflush(stdout);
count_sort(test_array, n); count_sort(test_array, n);
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {