Repositories » libk0
Clone URL:  
Pushed to one repository · View In Graph Contained in tip

Removed an extra unused variable from nrinsert(). Renamed a variable
in insert().

Changeset cd3be3421346

Parent 30fb43727ad0

by Rup Palchowdhury

Changes to 2 files · Browse files at cd3be3421346 Showing diff from parent 30fb43727ad0 Diff from another changeset...

Change 1 of 2 Show Entire File ktree.c Stacked
 
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
 
61
62
63
64
 
65
66
67
 
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
 
60
61
62
 
63
64
65
66
@@ -19,41 +19,40 @@
  }  }   -TNode *insert(TNode *p, TNode *n, +TNode *insert(TNode *treep, TNode *n,   int (*tnodecmp)(void*, void*),   int (*match_handler)(void*, void*))  {   int cmp; - if (p == NULL) + if (treep == NULL)   return n; - cmp = (*tnodecmp)(n->data, p->data); + cmp = (*tnodecmp)(n->data, treep->data);   if (cmp == 0) {   if (match_handler != NULL) - (*match_handler)(p->data, n->data); + (*match_handler)(treep->data, n->data);   }   else if (cmp < 0) - p->l = insert(p->l, n, tnodecmp, match_handler); + treep->l = insert(treep->l, n, tnodecmp, match_handler);   else - p->r = insert(p->r, n, tnodecmp, match_handler); - return p; + treep->r = insert(treep->r, n, tnodecmp, match_handler); + return treep;  }    TNode *nrinsert(TNode *treep, TNode *newp,   int (*tnodecmp)(void*, void*),   int (*match_handler)(void*, void*))  { - TNode *r, **p; + TNode **p;   int cmp;   if (treep == NULL)   return newp; - r = treep;   p = &treep;   while (*p != NULL) {   cmp = (*tnodecmp)(newp->data, (*p)->data);   if (cmp == 0) {   if (match_handler != NULL)   (*match_handler)((*p)->data, newp->data); - return r; + return treep;   }   else if (cmp < 0)   p = &((*p)->l); @@ -61,7 +60,7 @@
  p = &((*p)->r);   }   *p = newp; - return r; + return treep;  }    TNode *tlookup(TNode *p, TNode *n, int (*tnodecmp)(void*, void*))
Change 1 of 3 Show Entire File test.c Stacked
 
17
18
19
20
 
21
22
23
 
50
51
52
 
53
54
55
 
56
57
58
 
64
65
66
67
68
 
 
69
70
71
72
73
74
75
76
77
 
17
18
19
 
20
21
22
23
 
50
51
52
53
54
55
 
56
57
58
59
 
65
66
67
 
 
68
69
70
71
72
73
74
 
75
76
77
@@ -17,7 +17,7 @@
  Post *pp;     /* hash table test */ - + /*   const int NHASH = 3;   Node *htab[NHASH];   for (i = 0; i < NHASH; i++) @@ -50,9 +50,10 @@
  }   else   printf("Not found\n"); + */     /* tree test */ - /* +   TNode *found;   t = NULL;   for (i = 0; i < NUMNODES; i++) @@ -64,14 +65,13 @@
  found = nrtlookup(t, newtnode(newpost("h", 1)), postcmp);   if (found != NULL)   printpost(found->data, "nrtlookup: %s %d\n"); - */ - /* + +   printf("inorder:\n");   applyinorder(t, printpost, "%s %d\n");   printf("\n");   printf("postorder:\n");   applypostorder(t, printpost, "%s %d\n"); - */     /* list test */