Bonjour a tous,
J'ai un petit probleme avec ce code que je viens d'ecrire,et je ne trouve pas le probleme....
Desolée, mais les noms des fonctions sont tous en portugais ^^'
En faites dans mon MAIN, j'ai la fonction "reserva" avec um nombre (65600), le probleme viens dans ma fonction "reserva" ou normalement il ne devrait rentrer que a la troisieme condition, comme resultat final bien sur !
Mais dans mon terminal, il rentre dans la premiere condition ! Et je ne comprends pas pourquoi ! Une aide serait la bienvenue.
Merci,

Damien

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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;
}