Assembly Language for Beginners

(nextflipdebug2) #1

3.18. C++


int M_color; // 0 - Red, 1 - Black
struct tree_node M_parent;
struct tree_node
M_left;
struct tree_node *M_right;
};


struct tree_struct
{
int M_key_compare;
struct tree_node M_header;
size_t M_node_count;
};


const char* ALOT_OF_TABS="\t\t\t\t\t\t\t\t\t\t\t";


void dump_as_tree (int tabs, struct tree_node n)
{
void
point_after_struct=((char*)n)+sizeof(struct tree_node);


printf ("%d\n", *(int*)point_after_struct);

if (n->M_left)
{
printf ("%.sL-------", tabs, ALOT_OF_TABS);
dump_as_tree (tabs+1, n->M_left);
};
if (n->M_right)
{
printf ("%.
sR-------", tabs, ALOT_OF_TABS);
dump_as_tree (tabs+1, n->M_right);
};
};


void dump_map_and_set(struct tree_struct *m)
{
printf ("root----");
dump_as_tree (1, m->M_header.M_parent);
};


int main()
{
std::set s;
s.insert(123);
s.insert(456);
printf ("123, 456 has been inserted\n");
dump_map_and_set ((struct tree_struct )(void)&s);
s.insert(11);
s.insert(12);
printf ("\n");
printf ("11, 12 has been inserted\n");
dump_map_and_set ((struct tree_struct )(void)&s);
s.insert(100);
s.insert(1001);
printf ("\n");
printf ("100, 1001 has been inserted\n");
dump_map_and_set ((struct tree_struct )(void)&s);
s.insert(667);
s.insert(1);
s.insert(4);
s.insert(7);
printf ("\n");
printf ("667, 1, 4, 7 has been inserted\n");
dump_map_and_set ((struct tree_struct )(void)&s);
printf ("\n");
};


Listing 3.118: GCC 4.8.1

123, 456 has been inserted
root----123

Free download pdf