Data Str &amp; Algorithm HW Solutions 77

# Data Str &amp; Algorithm HW Solutions 77 - 4 pointers...

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

77 update[i] = x; // Keep track of end at level i } if (!KEcomp.eq(K, x->forward[0]->value)) return; // Value not in list x = forward[0]; // Pointing at node to delete for (i=0; i<=x->level; i++) // Fix up the pointers update[i]->forward[i] = x->forward[i]; Elem temp = x->value; delete x; return temp; } 12.5 This is something of a trick question. There is no good access method for f nding the i th node, other than to count over i pointers at level 0. template <class Key, class Elem, class KEComp, class EEComp> SkipNode<Elem>* SkipList::ithnode(int i) { SkipNode<Elem>* curr = head; for(int j=0; j<i; j++) { if (curr->forward[0] == NULL) return NULL; // No ith node in list curr = curr->forward[0]; } return curr; } 12.6 A regular array cell requires 8 bytes (a value. A sparse matrix cell requires
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 4 pointers, two indices and a value for a total of 28 bytes. If the array con-tains more than 8/28 or 29% non-zero-valued elements, then the regular array representation will be more space ef f cient. Note that this ignores the space required for the row and column headers, which will be 10( M + N ) for and M × N matrix. 12.7 \\ Written so that tail returns the tail of the list MLnode* reverse(MLnode* rt) { if (rt == NULL) return NULL; rt->child = reverse(rt->child); if (rt->next == NULL) return rt; // Only elem on list MLnode* newrt = reverse(rt->next); rt->next->next = rt; // rt->next still points at // original next node // (which is now tail of // reversed list) rt->next = NULL; return newrt;...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online