1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
| #include <stdlib.h>
#include <stdio.h>
typedef struct sLL{
int linicial;
int lfinal;
struct sLL *next;
}LL;
LL * init(){
LL *aux=NULL;
aux=(LL *) malloc(sizeof(LL));
aux->linicial=0;
aux->lfinal=65535;
aux->next=NULL;
return aux;
}
LL * reserva(LL *l1,int n,int *reservado){
if(l1 && (((l1->lfinal)-(l1->linicial))<= n)) {
*reservado=l1->linicial;
l1->linicial+=n;
return l1;
}
else if(l1 && (((l1->lfinal) - (l1->linicial) > n))) {
l1->next=reserva(l1->next,n,reservado);
return l1;
}
else{
*reservado=-1;
return l1;
}
}
LL * liberta(LL *l1,int lugar, int n){
}
void showLL(LL *l1,int *reservado){
if(l1){
printf("[ %d , %d ]-->",l1->linicial,l1->lfinal);
showLL(l1->next,reservado);
}
else{
printf("NULL\n *reservado: %d\n",*reservado);
}
}
int main(){
LL *l1=NULL;
int *reservado;
int reservado2=0;
reservado=&reservado2;
l1=init();
l1=reserva(l1,65600,reservado);
showLL(l1,reservado);
return 0;
} |
Partager