Skip to content

Commit 522ab32

Browse files
committed
sorting algorithms
1 parent dfe4642 commit 522ab32

File tree

3 files changed

+49
-4
lines changed

3 files changed

+49
-4
lines changed

100-main.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include "sort.h"
4+
5+
/**
6+
* main - Entry point
7+
*
8+
* Return: Always 0
9+
*/
10+
int main(void)
11+
{
12+
int array[] = {19, 48, 99, 71, 13, 52, 96, 73, 86, 7};
13+
size_t n = sizeof(array) / sizeof(array[0]);
14+
15+
print_array(array, n);
16+
printf("\n");
17+
shell_sort(array, n);
18+
printf("\n");
19+
print_array(array, n);
20+
return (0);
21+
}

101-O

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
O(n)
2+
O(n^2)
3+
O(n^2)

sort.h

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
1-
#ifndef SORT_H
2-
#define SORT_H
3-
1+
#ifndef _SORT_H_
2+
#define _SORT_H_
3+
#include <stddef.h>
44
#include <stdio.h>
55
#include <stdlib.h>
66

7+
/**
8+
* enum bool - Enumration of Boolean values.
9+
* @false: is equals 0.
10+
* @true: is equals 1.
11+
*/
12+
typedef enum bool
13+
{
14+
false = 0,
15+
true
16+
} bool;
717

818
/**
919
* struct listint_s - Doubly linked list node
@@ -19,10 +29,21 @@ typedef struct listint_s
1929
struct listint_s *next;
2030
} listint_t;
2131

22-
void print_array(const int *array, size_t size);
2332
void print_list(const listint_t *list);
33+
void print_array(const int *array, size_t size);
2434
void bubble_sort(int *array, size_t size);
2535
void insertion_sort_list(listint_t **list);
2636
void selection_sort(int *array, size_t size);
37+
void quick_sort(int *array, size_t size);
38+
void shell_sort(int *array, size_t size);
39+
void quick_sort_hoare(int *array, size_t size);
40+
void counting_sort(int *array, size_t size);
41+
void cocktail_sort_list(listint_t **list);
42+
void merge_sort(int *array, size_t size);
43+
void heap_sort(int *array, size_t size);
44+
void radix_sort(int *array, size_t size);
45+
void bitonic_sort(int *array, size_t size);
46+
void quick_sort_hoare(int *array, size_t size);
47+
2748

2849
#endif

0 commit comments

Comments
 (0)