Quiz 5, Thursday, 11/13

(20 minutes. Open notes)


Below I have attached the code for recursiveQuickSort. Imagine that we print the contents of the array list after each call to recursiveQuickSort in the code below. Suppose that the array list initially contains:
3 	8 	2 	1 	5 	7
What is the output produced by this code?
	public static void recursiveQuickSort(int[] list, int first, int last) {
		if(first < last)
		{
			int p = partition(list, first, last);
			printList(list);
			recursiveQuickSort(list, first, p-1);
			recursiveQuickSort(list, p+1, last);
		}
	}

	public static int partition(int[] list, int first, int last) {
		int p = first;
		for(int n = p+1; n <= last; n++)
			if(list[n] < list[p])
			{
				swap(list, n, p+1);
				swap(list, p, p+1);
				p++;
			}
		return p;
	}
`