CS 122 Winter 2001 instr. Jeff Horn YOUR NAME ____________________
Quiz 1 (take-home) March 6, 2001, due March 14, 2001
QUESTION 1 Given the
following class, answer the questions:
class Ewok}
{
public static HowManyEwoksSoFar = 0;
private int health;
private String name;
public Ewok()
{ health = 100; HowManyEwoksSoFar++;}
public void change_Name(String new_name)
{ name = new_name; }
public void hit(int how_hard)
{ health -= how_hard;}
public void heal(int how_much)
{ health += how_much;}
public boolean undead()
{ return (health < 0); }
QUESTION 2 Given an initially unsorted array:
58
21
43
12
8
89
91
104
93
4
17
33
public Sort()
{
for(right = lastElementIndex; right >= 0, right--)
Swap(right, MaxInRange(0,right) );
}
}
1.What would "MaxInRange"
return the first time it is called?
2.What would the
array look like after three iterations through the main sort loop?
3.If the array were already sorted at the beginning, how many swaps would be made by our selection sort?