Digital Search Tree

Temptytree tpatriciamallocsizeofpatriciatree

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ot; Patricia Search Patricia Search Patricia search(patricia t, unsigned k) { /*search the Patricia tree t; return the last node y encountered; if k = y ­>data.key, the key is in the tree */ Patricia p, y; If (!t) return NULL; /* empty tree*/ y=t­>left_child; p=t; while (y­>bit_number > p­>bit_number){ p=y; y=(bit(k, y­>bit_number)) ? y­>right_child : y­>left_child; } return y; Patricia 的 Insert Patricia void insert (patricia *t, element x){ /* insert x into the Patricia tree *t */ patricia s, p, y, z; int i; if (!(*t)) { /* empty tree*/ *t = (patricia)malloc(sizeof(patricia_tree)); if (IS_FULL(*t)) { fprintf(stderr, “The memory is full\n”) ; exit(1); } (*t)­>bit_number = 0 (*t)­>data = x; (*t)­>left_child = *t; } y = search(*t,x.key); if (x.key == y­>data.key) { fprintf(stderr, “The key is in the tree. Insertion fails.\n”); exit(1);} /* find the first bit where x.key and y­>data.key differ*/ /* find the first bit where x.key and y­>data.key differ*/ for(i = 1; bit (x.key,i) == bit(y­>data.key,i); i++ ); /* search tree using the first i­1 bits*/ s = (*t)­>left_child; p = *t; while (s­&g...
View Full Document

This note was uploaded on 02/07/2014 for the course CSE 100 taught by Professor Staff during the Summer '08 term at UCSD.

Ask a homework question - tutors are online