AVL tree/C: Difference between revisions

m
Fixed syntax highlighting.
(C entry is almost 20 HD screens now, moving to separate page)
 
m (Fixed syntax highlighting.)
 
(One intermediate revision by one other user not shown)
Line 1:
===Code===
<langsyntaxhighlight lang="c">#include <stdio.h>
#include <stdlib.h>
#include <time.h>
Line 182:
 
return 0;
}</langsyntaxhighlight>
{{out}}
<pre>
Line 238:
 
<tt>AvlTree.h</tt>
<langsyntaxhighlight lang="c">#ifndef AVLTREE_INCLUDED
#define AVLTREE_INCLUDED
 
Line 260:
void *Node_GetData (Node n);
 
#endif</langsyntaxhighlight>
 
<tt>AvlTree.c</tt>
<langsyntaxhighlight lang="c">#include <stdio.h>
#include <stdlib.h>
#include "AvlTree.h"
Line 315:
 
t = malloc (sizeof (*t));
t->root = NULL;
t->comp = comp;
t->print = print;
Line 859 ⟶ 860:
 
return n;
}</langsyntaxhighlight>
 
And here's the example which shows how to use the package. It creates in an endless loop random numbers between 0..999 and stores the number (the key) together with its square root (the value) in the tree. If an element with the given key is already in tree, it will be deleted.
 
<langsyntaxhighlight lang="c">#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
Line 923 ⟶ 924:
 
return 0;
}</langsyntaxhighlight>
 
After a number of iterations, the tree will look similar to this:
9,485

edits