quiz2 - Name: 1.124 Quiz 2 Thursday November 9, 2000 Time:...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Name: 1.124 Quiz 2 Thursday November 9, 2000 Time: 1 hour 20 minutes Answer all questions. All questions carry equal marks. Question 1. Show the steps that are involved in sorting the string SORTME using the quicksort algorithm given below. #include <iostream.h> void quicksort(char *a, int l, int r); main() { char str[8] = "9SORTME"; // 9 is a sentinel. quicksort(str, 1, 6); } inline void swap(char *a, int i, int j) { char tmp = a[i]; a[i] = a[j]; a[j] = tmp; cout << a+1 << endl; // Print out the array, excluding the sentinel. } void quicksort(char *a, int l, int r) { if (r > l) { char v = a[r]; int i = l - 1; int j = r; while (1) { while(a[++i] < v); while(a[--j] > v); if (j <= i) break; swap(a, i, j); } swap(a, r, i); quicksort(a, l, i-1); quicksort(a, i+1, r); } } S O R T M E Answer:
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Question 2. Show how you would translate the bold portions of the following C++ code into Java. #include <iostream.h> class Shape { private: float x, y; public: Shape(float a, float b) { x = a; y = b; } virtual float compute_area() = 0; virtual void print() {
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 8

quiz2 - Name: 1.124 Quiz 2 Thursday November 9, 2000 Time:...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online