commit
ea6b22e51c
@ -0,0 +1,22 @@
|
|||||||
|
int is_prime(int nb)
|
||||||
|
{
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
|
i = 2;
|
||||||
|
while (i <= nb / i)
|
||||||
|
{
|
||||||
|
if (nb % i == 0)
|
||||||
|
return (1);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int find_next_prime(int nb)
|
||||||
|
{
|
||||||
|
if (nb <= 2)
|
||||||
|
return (2);
|
||||||
|
while (!(is_prime(nb) == 0))
|
||||||
|
nb++;
|
||||||
|
return (nb);
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
int my_atoi(char *str)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int posi;
|
||||||
|
int num;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
posi = 1;
|
||||||
|
num = 0;
|
||||||
|
while (str[i] == 32 || (str[i] >= 9 && str[i] <= 13))
|
||||||
|
i++;
|
||||||
|
while (str[i] == '-' || str[i] == '+')
|
||||||
|
{
|
||||||
|
if (str[i] == '-')
|
||||||
|
posi = posi * -1;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
while (str[i] >= 48 && str[i] <= 57)
|
||||||
|
{
|
||||||
|
num = num * 10;
|
||||||
|
num = num + (str[i] - 48);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (num * posi);
|
||||||
|
}
|
@ -0,0 +1,101 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#define TYPE int
|
||||||
|
|
||||||
|
typedef struct maillon
|
||||||
|
{
|
||||||
|
TYPE v;
|
||||||
|
struct maillon *suiv;
|
||||||
|
} Maillon, *File;
|
||||||
|
|
||||||
|
File filenouv(void)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool vide(File f)
|
||||||
|
{
|
||||||
|
return f==NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
TYPE tete(File f)
|
||||||
|
{
|
||||||
|
if(vide(f))
|
||||||
|
{
|
||||||
|
printf("OpÃration interdite\n");
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
return f->suiv->v;
|
||||||
|
}
|
||||||
|
|
||||||
|
int longueur(File f)
|
||||||
|
{
|
||||||
|
if(vide(f))
|
||||||
|
{
|
||||||
|
printf("OpÃration interdite\n");
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
Maillon *m;
|
||||||
|
int i;
|
||||||
|
i = 1;
|
||||||
|
m = f->suiv;
|
||||||
|
while(m != f)
|
||||||
|
{
|
||||||
|
++i
|
||||||
|
m = m->suiv;
|
||||||
|
}
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*void afficher(File f)
|
||||||
|
{
|
||||||
|
if(vide(f))
|
||||||
|
return;
|
||||||
|
Maillon *m;
|
||||||
|
m = f->suiv;
|
||||||
|
while(m != f)
|
||||||
|
{
|
||||||
|
printf("%d\t", m->v);
|
||||||
|
m = m->suiv;
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}*/
|
||||||
|
|
||||||
|
File supprTete(File f)
|
||||||
|
{
|
||||||
|
if(vide(f))
|
||||||
|
{
|
||||||
|
printf("OpÃration interdite\n");
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
if(f == f->suiv)
|
||||||
|
{
|
||||||
|
free(f);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
Maillon *tmp;
|
||||||
|
tmp = f->suiv;
|
||||||
|
tmp->suiv = tmp->suiv->suiv;
|
||||||
|
free(f);
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
File addQueue(File f, TYPE x)
|
||||||
|
{
|
||||||
|
Maillon *m;
|
||||||
|
if(!m = (Maillon *)malloc(sizeof(Maillon)))
|
||||||
|
{
|
||||||
|
printf("ProblÃme Malloc\n");
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
m->v = x;
|
||||||
|
if(vide(f))
|
||||||
|
{
|
||||||
|
f = m;
|
||||||
|
m->suiv = m;
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
m->suiv = f->suiv;
|
||||||
|
f->suiv = m;
|
||||||
|
f = m;
|
||||||
|
return f;
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
int my_is_prime(int nb)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 2;
|
||||||
|
if (nb < 2)
|
||||||
|
return (0);
|
||||||
|
while (i <= nb / i)
|
||||||
|
{
|
||||||
|
if (nb % i == 0)
|
||||||
|
return (0);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (1);
|
||||||
|
}
|
@ -0,0 +1,84 @@
|
|||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
int char_is_separator(char c, char *charset)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (charset[i] != '\0')
|
||||||
|
{
|
||||||
|
if (c == charset[i])
|
||||||
|
return (1);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
if (c == '\0')
|
||||||
|
return (1);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int count_words(char *str, char *charset)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int words;
|
||||||
|
|
||||||
|
words = 0;
|
||||||
|
i = 0;
|
||||||
|
while (str[i] != '\0')
|
||||||
|
{
|
||||||
|
if (char_is_separator(str[i + 1], charset) == 1
|
||||||
|
&& char_is_separator(str[i], charset) == 0)
|
||||||
|
words++;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (words);
|
||||||
|
}
|
||||||
|
|
||||||
|
void write_word(char *dest, char *from, char *charset)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (char_is_separator(from[i], charset) == 0)
|
||||||
|
{
|
||||||
|
dest[i] = from[i];
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
dest[i] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
void write_split(char **split, char *str, char *charset)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int j;
|
||||||
|
int word;
|
||||||
|
|
||||||
|
word = 0;
|
||||||
|
i = 0;
|
||||||
|
while (str[i] != '\0')
|
||||||
|
{
|
||||||
|
if (char_is_separator(str[i], charset) == 1)
|
||||||
|
i++;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
j = 0;
|
||||||
|
while (char_is_separator(str[i + j], charset) == 0)
|
||||||
|
j++;
|
||||||
|
split[word] = (char*)malloc(sizeof(char) * (j + 1));
|
||||||
|
write_word(split[word], str + i, charset);
|
||||||
|
i += j;
|
||||||
|
word++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
char **my_split(char *str, char *charset)
|
||||||
|
{
|
||||||
|
char **split;
|
||||||
|
int words;
|
||||||
|
|
||||||
|
words = count_words(str, charset);
|
||||||
|
split = (char**)malloc(sizeof(char*) * (words + 1));
|
||||||
|
split[words] = 0;
|
||||||
|
write_split(split, str, charset);
|
||||||
|
return (split);
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
int sqrt(int nb)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
if (nb < 0)
|
||||||
|
return (0);
|
||||||
|
while (i < 46341 || i < nb)
|
||||||
|
{
|
||||||
|
if (i * i == nb)
|
||||||
|
return (i);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
char *my_strcat(char *dest, char *src)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int j;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
j = 0;
|
||||||
|
while (dest[i] != '\0')
|
||||||
|
i++;
|
||||||
|
while (src[j] != '\0')
|
||||||
|
{
|
||||||
|
dest[i] = src[j];
|
||||||
|
i++;
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
dest[i] = '\0';
|
||||||
|
return (dest);
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
int my_strcmp(char *s1, char *s2)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (s1[i])
|
||||||
|
{
|
||||||
|
if (s1[i] != s2[i])
|
||||||
|
return (s1[i] - s2[i]);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (s1[i] - s2[i]);
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
char *my_strcpy(char *dest, char *src)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (src[i] != '\0')
|
||||||
|
{
|
||||||
|
dest[i] = src[i];
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
dest[i] = '\0';
|
||||||
|
return (dest);
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
char *my_strdup(char *src)
|
||||||
|
{
|
||||||
|
int size;
|
||||||
|
char *new;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
size = 0;
|
||||||
|
i = 0;
|
||||||
|
while (src[size])
|
||||||
|
size++;
|
||||||
|
new = (char*)malloc(sizeof(char) * (size + 1));
|
||||||
|
if (!new)
|
||||||
|
return (NULL);
|
||||||
|
while (src[i])
|
||||||
|
{
|
||||||
|
new[i] = src[i];
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
new[i] = '\0';
|
||||||
|
return (new);
|
||||||
|
}
|
@ -0,0 +1,82 @@
|
|||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
int sep_size(char *str)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (str[i])
|
||||||
|
i++;
|
||||||
|
return (i);
|
||||||
|
}
|
||||||
|
|
||||||
|
int full_size(int size, char **strs, char *sep)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int j;
|
||||||
|
int len;
|
||||||
|
|
||||||
|
len = 0;
|
||||||
|
i = 0;
|
||||||
|
j = 0;
|
||||||
|
while (i < size)
|
||||||
|
{
|
||||||
|
j = 0;
|
||||||
|
while (strs[i][j])
|
||||||
|
{
|
||||||
|
len++;
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
if (i + 1 < size)
|
||||||
|
len += sep_size(sep);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (len);
|
||||||
|
}
|
||||||
|
|
||||||
|
void write_str(int size, char **strs, char *sep, char *str)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int j;
|
||||||
|
int k;
|
||||||
|
|
||||||
|
i = -1;
|
||||||
|
j = 0;
|
||||||
|
k = 0;
|
||||||
|
while (++i < size)
|
||||||
|
{
|
||||||
|
j = -1;
|
||||||
|
while (strs[i][++j])
|
||||||
|
{
|
||||||
|
str[k] = strs[i][j];
|
||||||
|
k++;
|
||||||
|
}
|
||||||
|
j = -1;
|
||||||
|
while (i + 1 < size && sep[++j])
|
||||||
|
{
|
||||||
|
str[k] = sep[j];
|
||||||
|
k++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
str[k] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
char *my_strjoin(int size, char **strs, char *sep)
|
||||||
|
{
|
||||||
|
char *str;
|
||||||
|
|
||||||
|
if (size > 0)
|
||||||
|
{
|
||||||
|
if (!(str = (char*)
|
||||||
|
malloc(sizeof(char) * (full_size(size, strs, sep) + 1))))
|
||||||
|
return (NULL);
|
||||||
|
write_str(size, strs, sep, str);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!(str = (char*)malloc(sizeof(char) * 1)))
|
||||||
|
return (NULL);
|
||||||
|
str[0] = '\0';
|
||||||
|
}
|
||||||
|
return (str);
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
int my_strlen(char *str)
|
||||||
|
{
|
||||||
|
int len;
|
||||||
|
|
||||||
|
len = 0;
|
||||||
|
while (str[len] != '\0')
|
||||||
|
len++;
|
||||||
|
return (len);
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
char *my_strncat(char *dest, char *src, unsigned int nb)
|
||||||
|
{
|
||||||
|
unsigned int i;
|
||||||
|
unsigned int j;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
j = 0;
|
||||||
|
while (dest[i] != '\0')
|
||||||
|
i++;
|
||||||
|
while (src[j] != '\0' && j < nb)
|
||||||
|
{
|
||||||
|
dest[i] = src[j];
|
||||||
|
i++;
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
dest[i] = '\0';
|
||||||
|
return (dest);
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
int my_strncmp(char *s1, char *s2, unsigned int n)
|
||||||
|
{
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
if (n == 0)
|
||||||
|
return (0);
|
||||||
|
while (s1[i] == s2[i] && s1[i] != '\0' && i < n - 1)
|
||||||
|
i++;
|
||||||
|
return (s1[i] - s2[i]);
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
char *my_strncpy(char *dest, char *src, unsigned int n)
|
||||||
|
{
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (i < n && src[i] != '\0')
|
||||||
|
{
|
||||||
|
dest[i] = src[i];
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
while (i < n)
|
||||||
|
{
|
||||||
|
dest[i] = '\0';
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (dest);
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
char *strstr(char *str, char *to_find)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int j;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
j = 0;
|
||||||
|
if (!(to_find[j]))
|
||||||
|
return (str);
|
||||||
|
while (str[i])
|
||||||
|
{
|
||||||
|
if (str[i] == to_find[0])
|
||||||
|
{
|
||||||
|
j = 0;
|
||||||
|
while (str[i + j] && str[i + j] == to_find[j])
|
||||||
|
j++;
|
||||||
|
if (to_find[j] == '\0')
|
||||||
|
return (&str[i]);
|
||||||
|
}
|
||||||
|
if (to_find[j] == '\0')
|
||||||
|
return (&str[i]);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
void ultimate_div_mod(int *a, int *b)
|
||||||
|
{
|
||||||
|
int buf_a;
|
||||||
|
int buf_b;
|
||||||
|
|
||||||
|
buf_a = *a;
|
||||||
|
buf_b = *b;
|
||||||
|
*a = buf_a / buf_b;
|
||||||
|
*b = buf_a % buf_b;
|
||||||
|
}
|
Loading…
Reference in new issue