22S-Section-Solution

22S-Section-Solution - CS106X Autumn 2009 Handout 22S...

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

View Full Document Right Arrow Icon
CS106X Handout 22S Autumn 2009 October 28 th – 29 th , 2009 Section Solution Solution 1: The Sparse String Vector a. Present implementations for the constructor and destructor. SparseStringVector::SparseStringVector(int arrayLength, int groupSize) { this->arrayLength = arrayLength; this->groupSize = groupSize; numGroups = arrayLength / groupSize; groups = new group[numGroups]; for (int i = 0; i < numGroups; i++) { groups[i].bitmap = new bool[this->groupSize]; for (int j = 0; j < this->groupSize; j++) { groups[i].bitmap[j] = false; } } } SparseStringVector::~SparseStringVector() { for (int i = 0; i < numGroups; i++) { delete[] groups[i].bitmap; } delete[] groups; } b. Now implement the more involved insert function, which ensures that the string received as str stored in the proper Vector<string> within the proper group and that the proper bool in the bitmap is set. bool SparseStringVector::insert(int index, string str) { int group = index / groupSize; int indexWithinBitmap = index % groupSize;
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.

Page1 / 3

22S-Section-Solution - CS106X Autumn 2009 Handout 22S...

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