Commit e584115e authored by MEZHOUD_MELISSA's avatar MEZHOUD_MELISSA
Browse files

update tas.c

parent bb4b6ace
Pipeline #4650 failed with stage
in 6 seconds
#include <stdio.h>
#include "tas.h"
#include "tas.c"
#include <time.h>
int main()
{int taille ;
int v ;
int i ;
int cmp;
printf("inserez la taille de l'arbre \n");
scanf("%d",&taille);
......@@ -19,7 +25,7 @@ printf("inserez les valeurs de l'arbre \n");
for(i = 0; i <=taille ; i++){
for(i = 1; i <=taille ; i++){
printf("%d\n",montas->tab[i]);}
return 0;
}
......
#include <stdlib.h>
#include "tas.h"
#include <time.h>
Tas* createtas(int taille)
{
Tas *tas = malloc(sizeof(Tas));
......@@ -11,30 +13,40 @@ Tas* createtas(int taille)
return tas;
}
void AJOUT(Tas *tas, int value)
{
if(tas->size >= tas->capacity)
{printf("impossible !le tas est plein\n");}
tas->tab[tas->size] = value;
tas->size++;
void reorganize(Tas *tas){
int tmp;
int i;
int echange=0;int E=tas->size;
int size = tas->size;
int index = size/2;
int tabE[10];
while(tas->tab[index] < tas->tab[size] && size>1)
{
tmp = tas->tab[size];
tas->tab[size] = tas->tab[index];
tas->tab[index] = tmp;
echange++;
index/=2;
size/=2;
}
tabE[tas->size]=echange;
{printf("nbr d'echanges %d\n",tabE[tas->size]);}
}
void AJOUT(Tas *tas, int value)
{
if(tas->size >= tas->capacity)
{printf("impossible !le tas est plein\n");}
tas->size++;
tas->tab[tas->size] = value;
reorganize(tas);
}
......@@ -15,5 +15,6 @@ Tas{
Tas* createtas(int capacity);
void AJOUT(Tas *tas, int value);
void reorganize(Tas *Tas);
#endif //CGI_HEAP_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment