Browse Source

rename to counting sort

Chris Cromer 2 weeks ago
parent
commit
02ea6050e9
Signed by: Chris Cromer <chris@cromer.cl> GPG Key ID: 39CC813FF3C8708A
6 changed files with 18 additions and 18 deletions
  1. 1
    1
      Makefile
  2. 1
    1
      src/counting_sort.c
  3. 3
    3
      src/include/counting_sort.h
  4. 9
    9
      src/sort.c
  5. 1
    1
      test/Makefile
  6. 3
    3
      test/test.c

+ 1
- 1
Makefile View File

@@ -1,7 +1,7 @@
1 1
 CC=gcc
2 2
 CFLAGS=-Wall -Isrc/include -DDEBUG -g
3 3
 LDFLAGS=-lm
4
-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
4
+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
5 5
 OBJ=$(SRC:.c=.o)
6 6
 
7 7
 all: sort informe

src/count_sort.c → src/counting_sort.c View File

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

src/include/count_sort.h → src/include/counting_sort.h View File

@@ -13,7 +13,7 @@
13 13
  * 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.
14 14
  */
15 15
 
16
-#ifndef _SORT_COUNT
17
-	#define _SORT_COUNT
18
-	void count_sort(int *array, int n);
16
+#ifndef _SORT_COUNTING
17
+	#define _SORT_COUNTING
18
+	void counting_sort(int *array, int n);
19 19
 #endif

+ 9
- 9
src/sort.c View File

@@ -22,7 +22,7 @@
22 22
 #include "random.h"
23 23
 #include "timer.h"
24 24
 #include "bubble_sort.h"
25
-#include "count_sort.h"
25
+#include "counting_sort.h"
26 26
 #include "quick_sort.h"
27 27
 #include "bitonic_sort.h"
28 28
 #include "selection_sort.h"
@@ -49,7 +49,7 @@ void print_usage() {
49 49
 	fprintf(stdout, "  -q, --quick                usar quick sort\n");
50 50
 	fprintf(stdout, "  -b, --bubble               usar bubble sort\n");
51 51
 	fprintf(stdout, "  -B, --bitonic              usar bitonic sort\n");
52
-	fprintf(stdout, "  -c, --count                usar ordenamiento por conteo\n");
52
+	fprintf(stdout, "  -c, --counting             usar ordenamiento por conteo\n");
53 53
 	fprintf(stdout, "  -s, --selection            usar ordenamiento por selección\n");
54 54
 	fprintf(stdout, "  -n, --n=N                  la cantidad de elementos a ordenar, la\n");
55 55
 	fprintf(stdout, "                             cantidad predeterminado es 10\n");
@@ -183,7 +183,7 @@ int main (int argc, char **argv) {
183 183
 	int quick = 0;
184 184
 	int bubble = 0;
185 185
 	int bitonic = 0;
186
-	int count = 0;
186
+	int counting = 0;
187 187
 	int selection = 0;
188 188
 	int opt;
189 189
 	int long_index = 0;
@@ -193,7 +193,7 @@ int main (int argc, char **argv) {
193 193
 		{"quick",		no_argument,		0,	'q'},
194 194
 		{"bubble",		no_argument,		0,	'b'},
195 195
 		{"bitonic",		no_argument,		0,	'B'},
196
-		{"count",		no_argument,		0,	'c'},
196
+		{"counting",	no_argument,		0,	'c'},
197 197
 		{"selection",	no_argument,		0,	's'},
198 198
 		{"n",			required_argument,	0,	'n'},
199 199
 		{"elegir",		no_argument,		0,	'e'},
@@ -215,7 +215,7 @@ int main (int argc, char **argv) {
215 215
 				quick = 1;
216 216
 				bubble = 1;
217 217
 				bitonic = 1;
218
-				count = 1;
218
+				counting = 1;
219 219
 				selection = 1;
220 220
 				break;
221 221
 			case 'm':
@@ -231,7 +231,7 @@ int main (int argc, char **argv) {
231 231
 				bitonic = 1;
232 232
 				break;
233 233
 			case 'c':
234
-				count = 1;
234
+				counting = 1;
235 235
 				break;
236 236
 			case 's':
237 237
 				selection = 1;
@@ -296,7 +296,7 @@ int main (int argc, char **argv) {
296 296
 		}
297 297
 	}
298 298
 
299
-	if (!merge && !quick && !bubble && !bitonic && !count && !selection) {
299
+	if (!merge && !quick && !bubble && !bitonic && !counting && !selection) {
300 300
 		fprintf(stderr, "Error: No se seleccionó un algoritmo valido!\n");
301 301
 		print_usage();
302 302
 		return 4;
@@ -351,8 +351,8 @@ int main (int argc, char **argv) {
351 351
 		end_sort();
352 352
 	}
353 353
 
354
-	// O(n^2)
355
-	if (count) {
354
+	// O((1/2) * n^2 - (1/2) * n)
355
+	if (counting) {
356 356
 		start_sort("Count sort corriendo... ", n);
357 357
 		count_sort(work_array, n);
358 358
 		end_sort();

+ 1
- 1
test/Makefile View File

@@ -3,7 +3,7 @@ CFLAGS=-Wall -I../src/include -DDEBUG -g
3 3
 SRC=test.c
4 4
 OBJ=$(SRC:.c=.o)
5 5
 
6
-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
6
+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
7 7
 
8 8
 all: test
9 9
 

+ 3
- 3
test/test.c View File

@@ -19,7 +19,7 @@
19 19
 #include <unistd.h>
20 20
 #include "random.h"
21 21
 #include "bubble_sort.h"
22
-#include "count_sort.h"
22
+#include "counting_sort.h"
23 23
 #include "selection_sort.h"
24 24
 #include "bitonic_sort.h"
25 25
 #include "merge_sort.h"
@@ -124,10 +124,10 @@ int main(int argc, char **argv) {
124 124
 		passed++;
125 125
 	}
126 126
 
127
-	// Test count sort
127
+	// Test counting sort
128 128
 	pass = 1;
129 129
 	memcpy(test_array, test_case, sizeof(int) * n);
130
-	fprintf(stdout, "\tcount sort: ");
130
+	fprintf(stdout, "\tcounting sort: ");
131 131
 	fflush(stdout);
132 132
 	count_sort(test_array, n);
133 133
 	for (i = 0; i < n; i++) {

Loading…
Cancel
Save