hw4solution

hw4solution - <?xml version="1.0"

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

View Full Document Right Arrow Icon

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

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

Unformatted text preview: <?xml version="1.0" encoding="ISO-8859-1" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>CS 32 Homework 4 Solution, Winter 2010</title> </head> <body> <div align="right"> Winter 2010 CS 32 </div> <div align="center"> <h2>Homework 4 Solution</h2> </div> <table cellpadding="3"> <colgroup width="60%"></colgroup> <colgroup></colgroup> <tr><td><a href="#P1">Problem 1</a></td> <td><a href="#P4">Problem 4</a></td></tr> <tr><td><a href="#P2">Problem 2</a></td> <td><a href="#P5">Problem 5</a></td></tr> <tr><td><a href="#P3">Problem 3</a></td> <td><a href="#P6">Problem 6</a></td></tr> </table> <h4><a id="P1"></a>Problem 1:</h4> <pre> // Sequence.h #ifndef SEQUENCE_INCLUDED #define SEQUENCE_INCLUDED #include &lt;cstddef> // for NULL <strong>template &lt;typename ItemType></strong> class Sequence { public: Sequence(); // Create an empty sequence. bool empty() const; // Return true iff the sequence is empty. int size() const; // Return the number of items in the sequence. bool insert(int pos, const ItemType&amp; value); // Insert value into the sequence so that it becomes the item at // position pos. The original item at position pos and those that // follow it end up at a position one higher than before. Return // true if 0 &lt;= pos &lt;= size() and the value could be inserted. // (It might not be, if the sequence has a fixed capacity, e.g., // because it's implemented using a fixed-size array.) Otherwise, // leave the sequence unchanged and return false. Notice that // if pos is equal to size(), the value is inserted at the end. bool insert(const ItemType&amp; value); // Let p be the smallest integer such that value &lt;= the item at // position p in the sequence; if no such item exists (i.e., // value > all items in the sequence), let p be size(). Insert // value into the sequence so that it becomes the item at position // p. The original item at position p and those that follow it end // up at a position one higher than before. Return true iff the // value could be inserted. (It might not be, if the sequence has a // fixed capacity.) bool erase(int pos); // If 0 &lt;= pos &lt; size(), remove the item at position pos from // the sequence (so that all items that followed this item end up at // a position one lower than before), and return true. Otherwise, // leave the sequence unchanged and return false. int remove(const ItemType&amp; value); // Erase all items from the sequence that == value. Return the // number of items removed (which will be 0 if no item == value). bool get(int pos, ItemType&amp; value) const; // If 0 &lt;= pos &lt; size(), copy into value the item at position pos // in the sequence and return true. Otherwise, leave value unchanged // and return false....
View Full Document

This note was uploaded on 03/08/2010 for the course COM SCI 32 taught by Professor Smallberg during the Spring '07 term at UCLA.

Page1 / 12

hw4solution - <?xml version="1.0"

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

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