Skip to content

Commit 33faec0

Browse files
committed
done
1 parent cade5df commit 33faec0

File tree

9 files changed

+263
-0
lines changed

9 files changed

+263
-0
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+
}

1000-main.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#include <stdlib.h>
2+
#include <stdio.h>
3+
#include "deck.h"
4+
5+
void print_deck(const deck_node_t *deck)
6+
{
7+
size_t i;
8+
char kinds[4] = {'S', 'H', 'C', 'D'};
9+
10+
i = 0;
11+
while (deck)
12+
{
13+
if (i)
14+
printf(", ");
15+
printf("{%s, %c}", deck->card->value, kinds[deck->card->kind]);
16+
if (i == 12)
17+
printf("\n");
18+
i = (i + 1) % 13;
19+
deck = deck->next;
20+
}
21+
}
22+
23+
deck_node_t *init_deck(const card_t cards[52])
24+
{
25+
deck_node_t *deck;
26+
deck_node_t *node;
27+
size_t i;
28+
29+
i = 52;
30+
deck = NULL;
31+
while (i--)
32+
{
33+
node = malloc(sizeof(*node));
34+
if (!node)
35+
return (NULL);
36+
node->card = &cards[i];
37+
node->next = deck;
38+
node->prev = NULL;
39+
if (deck)
40+
deck->prev = node;
41+
deck = node;
42+
}
43+
return (deck);
44+
}
45+
46+
int main(void)
47+
{
48+
card_t cards[52] = {
49+
{"Jack", CLUB}, {"4", HEART}, {"3", HEART}, {"3", DIAMOND}, {"Queen", HEART}, {"5", HEART}, {"5", SPADE}, {"10", HEART}, {"6", HEART}, {"5", DIAMOND}, {"6", SPADE}, {"9", HEART}, {"7", DIAMOND}, {"Jack", SPADE}, {"Ace", DIAMOND}, {"9", CLUB}, {"Jack", DIAMOND}, {"7", SPADE}, {"King", DIAMOND}, {"10", CLUB}, {"King", SPADE}, {"8", CLUB}, {"9", SPADE}, {"6", CLUB}, {"Ace", CLUB}, {"3", SPADE}, {"8", SPADE}, {"9", DIAMOND}, {"2", HEART}, {"4", DIAMOND}, {"6", DIAMOND}, {"3", CLUB}, {"Queen", CLUB}, {"10", SPADE}, {"8", DIAMOND}, {"8", HEART}, {"Ace", SPADE}, {"Jack", HEART}, {"2", CLUB}, {"4", SPADE}, {"2", SPADE}, {"2", DIAMOND}, {"King", CLUB}, {"Queen", SPADE}, {"Queen", DIAMOND}, {"7", CLUB}, {"7", HEART}, {"5", CLUB}, {"10", DIAMOND}, {"4", CLUB}, {"King", HEART}, {"Ace", HEART},
50+
};
51+
deck_node_t *deck;
52+
53+
deck = init_deck(cards);
54+
print_deck(deck);
55+
printf("\n");
56+
sort_deck(&deck);
57+
printf("\n");
58+
print_deck(deck);
59+
return (0);
60+
}

101-main.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include "sort.h"
4+
5+
/**
6+
* create_listint - Creates a doubly linked list from an array of integers
7+
*
8+
* @array: Array to convert to a doubly linked list
9+
* @size: Size of the array
10+
*
11+
* Return: Pointer to the first element of the created list. NULL on failure
12+
*/
13+
listint_t *create_listint(const int *array, size_t size)
14+
{
15+
listint_t *list;
16+
listint_t *node;
17+
int *tmp;
18+
19+
list = NULL;
20+
while (size--)
21+
{
22+
node = malloc(sizeof(*node));
23+
if (!node)
24+
return (NULL);
25+
tmp = (int *)&node->n;
26+
*tmp = array[size];
27+
node->next = list;
28+
node->prev = NULL;
29+
list = node;
30+
if (list->next)
31+
list->next->prev = list;
32+
}
33+
return (list);
34+
}
35+
36+
/**
37+
* main - Entry point
38+
*
39+
* Return: Always 0
40+
*/
41+
int main(void)
42+
{
43+
listint_t *list;
44+
int array[] = {19, 48, 99, 71, 13, 52, 96, 73, 86, 7};
45+
size_t n = sizeof(array) / sizeof(array[0]);
46+
47+
list = create_listint(array, n);
48+
if (!list)
49+
return (1);
50+
print_list(list);
51+
printf("\n");
52+
cocktail_sort_list(&list);
53+
printf("\n");
54+
print_list(list);
55+
return (0);
56+
}

102-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+
counting_sort(array, n);
18+
printf("\n");
19+
print_array(array, n);
20+
return (0);
21+
}

103-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+
merge_sort(array, n);
18+
printf("\n");
19+
print_array(array, n);
20+
return (0);
21+
}

104-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+
heap_sort(array, n);
18+
printf("\n");
19+
print_array(array, n);
20+
return (0);
21+
}

105-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+
radix_sort(array, n);
18+
printf("\n");
19+
print_array(array, n);
20+
return (0);
21+
}

106-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[] = {100, 93, 40, 57, 14, 58, 85, 54, 31, 56, 46, 39, 15, 26, 78, 13};
13+
size_t n = sizeof(array) / sizeof(array[0]);
14+
15+
print_array(array, n);
16+
printf("\n");
17+
bitonic_sort(array, n);
18+
printf("\n");
19+
print_array(array, n);
20+
return (0);
21+
}

107-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+
quick_sort_hoare(array, n);
18+
printf("\n");
19+
print_array(array, n);
20+
return (0);
21+
}

0 commit comments

Comments
 (0)