Everyone should work with one lab partner on this assignment.
This exercise should be quite helpful for Program 5. Take the code below as a starting point and complete the subsets method using a recursive strategy. When the code is run with a non-negative integer, n, the program should print all of the subsets of the numbers that include the integers from 1 through n. For example, if n is 3, one possible output appears below.
Subsets of 3
------------
{ }
{ 3 }
{ 2 }
{ 2 3 }
{ 1 }
{ 1 3 }
{ 1 2 }
{ 1 2 3 }
To get you started, please build upon the code below that John used to generate the sample output above.
public class Subsets
{
public void printAllSubsets (int number)
{
boolean [] used = new boolean[number];
System.out.println("Subsets of " + number);
System.out.println("------------");
subsets ( used, 0 );
}
}
You may run and test this code by placing an instance of the Subsets class on the BlueJ workbench. No driver is needed.
Take the Selection Sort code that we went over in lecture on Friday, April 8. Convert the solution so that instead of using two nested for loops, the solution is completely recursive and thus uses no for loops.
Before the end of the lab period, e-mail Mike at mthiesen@gmail.com the code that you developed. The subject of the message should be: CS221-xx inlab12 your-names. The xx is the number of your lab section.
Delete any BlueJ projects that you created and empty the recycle bin. Thanks.