La fonction ci-dessous ne présente aucune erreur lors de la compilation, mais je n'ai pas compris la transmission de la valeur du pointeur "r" (variable locale) à travers les appels de la fonction create_node().


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
65
66
67
68
69
 
 
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
 
// Node structure containing power and coefficient of variable 
	typedef struct Node { 
    			int coeff; 
    			int pow; 
    			struct Node* next; 
			}  Node; 
 
	//A) Function to create new node 
	void create_node(int x, int y, Node** temp) 
	{ 
    	Node *r, *z; 
    	z = *temp; 
    	if (z == NULL) 
		   {  
        	  r = (Node*)malloc(sizeof(struct Node)); 
        	  r->coeff = x; 
        	  r->pow = y; 
        	  *temp = r; 
       		  r->next = (Node*)malloc(sizeof(struct Node)); 
        	  r = r->next; 
        	  r->next = NULL; 
     	   } 
     	else 
		   { 
        	  r->coeff = x; 
              r->pow = y; 
              r->next = (Node*)malloc(sizeof(Node)); 
              r = r->next; 
              r->next = NULL; 
           } 
    } 
 
//B) Display Linked list 
void show(Node* node) 
{ 
    while (node->next != NULL) { 
        printf("%dx^%d", node->coeff, node->pow); 
        node = node->next; 
        if (node->coeff >= 0) { 
            if (node->next != NULL) 
                printf("+"); 
        } 
    } 
} 
 
 
 
int main()
{
	struct Node *poly1 = NULL, *poly2 = NULL, *poly = NULL; 
 
    // Create first list of 15x^3 + x^2 - 6x^1+ 10x^0 
    create_node(-15, 3, &poly1);
    create_node(1, 2, &poly1); 
    create_node(-6, 1, &poly1); 
    create_node(10, 0, &poly1);
 
 
    printf("\n Le Polynome : "); 
    show(poly1); 
 
	return 0;
}
Merci pour votre aide.