mirror of
https://git.hardenedbsd.org/hardenedbsd/HardenedBSD.git
synced 2024-12-26 04:54:07 +01:00
tree.3: the example code fixed
PR: 280566 Reviewed by: dougm
This commit is contained in:
parent
2edac5a60a
commit
503b7f94d8
@ -28,7 +28,7 @@
|
||||
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
.\"
|
||||
.Dd July 27, 2020
|
||||
.Dd August 2, 2024
|
||||
.Dt TREE 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
@ -675,6 +675,8 @@ To maintain the sum of the values in the tree, each element maintains
|
||||
the sum of its value and the sums from its left and right subtrees.
|
||||
Lastly, the internal structure of the tree is printed.
|
||||
.Bd -literal -offset 3n
|
||||
#define RB_AUGMENT(entry) sumaug(entry)
|
||||
|
||||
#include <sys/tree.h>
|
||||
#include <err.h>
|
||||
#include <stdio.h>
|
||||
@ -691,7 +693,7 @@ intcmp(struct node *e1, struct node *e2)
|
||||
return (e1->i < e2->i ? -1 : e1->i > e2->i);
|
||||
}
|
||||
|
||||
int
|
||||
void
|
||||
sumaug(struct node *e)
|
||||
{
|
||||
e->sum = e->i;
|
||||
@ -700,7 +702,6 @@ sumaug(struct node *e)
|
||||
if (RB_RIGHT(e, entry) != NULL)
|
||||
e->sum += RB_RIGHT(e, entry)->sum;
|
||||
}
|
||||
#define RB_AUGMENT(entry) sumaug(entry)
|
||||
|
||||
RB_HEAD(inttree, node) head = RB_INITIALIZER(&head);
|
||||
RB_GENERATE(inttree, node, entry, intcmp)
|
||||
@ -749,8 +750,7 @@ main(void)
|
||||
printf("%d\en", n->i);
|
||||
}
|
||||
print_tree(RB_ROOT(&head));
|
||||
printf("Sum of values = %d\n", RB_ROOT(&head)->sum);
|
||||
printf("\en");
|
||||
printf("\enSum of values = %d\en", RB_ROOT(&head)->sum);
|
||||
return (0);
|
||||
}
|
||||
.Ed
|
||||
|
Loading…
Reference in New Issue
Block a user