Data Structures & Alogs HW_Part_20

Data Structures & Alogs HW_Part_20 - 77 update[i =...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
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 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
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 10/31/2011 for the course BCN 3431 at University of Florida.

Page1 / 4

Data Structures &amp; Alogs HW_Part_20 - 77 update[i =...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online