<?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://en-cs-cs5142.coecis.cornell.edu/~your_netid/hw05-3a.html
For example, if your_netid is rjs476, 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://en-cs-cs5142.coecis.cornell.edu/~your_netid/php/hw05-3b.html
Create a user name and password for yourself.
Create a user name grader with a password of your choice. Please indicate the URL and the password for grader in your submission, so that the TA 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>
Test it and make sure it works with your username and password, and the grader username and password.
<?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.