<?php
function f($arr, $cmp) {
$result = null;
foreach ($arr as $val)
if ($result == null || $cmp($val, $result) > 0)
$result = $val;
return $result;
}
function comparator($x, $y) {
if ($x < $y) return -1;
if ($x == $y) return 0;
return 1;
}
$a = array(3,1,5,2);
$m = f($a, "comparator");
print "\$m is $m<br/>\n";
?>
<?php
class Store {
var $val = "";
function __get($propName) {
if ($propName == 'text')
return htmlentities($this->val);
if ($propName == 'rawText')
return $this->val;
}
function __set($propName, $value) {
if ($propName == 'text' || $propName == 'rawText')
$this->val = $value;
}
}
$s = new Store();
$s->text = "A <b>bold</b> string."; ?>
The text is "<?php print $s->text; ?>".<br/>
The raw text is "<?php print $s->rawText; ?>".<br/>
Follow the instructions from the lecture slides to create an HTML page that can be viewed from any web browser using the following URL:
http://www.cs.nyu.edu/~your_cims_id/hw05-3a.html
For example, if your_cims_id is hirzel, then the URL would be:
Use a .htaccess file to create a password protected HTML page that can be viewed from any web browser using the following URL:
http://www.cs.nyu.edu/~your_cims_id/php/hw05-3b.html
For example, with your_cims_id as hirzel, you get the following URL, which requires you to enter the user name student and the password Psh_P_8:
http://www.cs.nyu.edu/~hirzel/php/hw05-3b.html
Please create a user name grader. Please indicate the URL and the password for grader in your submission, so that Aditya Bhatia can access your web page.
In the same directory that you secured using a .htaccess file, create a PHP script hw05-3c.php with the following code:
<html><body>
<?php
if(!empty($_GET['who'])) { echo "Hi, {$_GET['who']}."; }
?>
<form action="<?php echo $_SERVER[PHP_SELF]; ?>" method="get">
Who shall be greeted: <input type="text" name="who" />
</form>
</body></html>
(See also http://www.cs.nyu.edu/~hirzel/php/hw05-3c.phps). Test it and make sure it works. For example, for your_cims_id hirzel, user name student, and password P_8sh_P, this URL runs the script for you:
http://www.cs.nyu.edu/~your_cims_id/php/hw05-3c.php
<?php
include 'PriorityQueue.inc';
$q = new PriorityQueue();
$q->insert(3.1);
$q->insert(4.2);
$q->insert(0.5);
$q->insert(1.9);
print $q->extractMax() . "<br/>\n";
print $q->extractMax() . "<br/>\n";
print $q->extractMax() . "<br/>\n";
print $q->extractMax() . "<br/>\n"; ?>
This should print 4.2, 3.1, 1.9, and 0.5, in other words, it should
output the previously-inserted numbers in descending order by value.
To solve this question, you need to put your code in a file
PriorityQueue.inc, so that the driver can pick it up via the
include statement. You can put the driver in a file
priorityQueueDriver.php.