quiz2

# quiz2 - Name 1.124 Quiz 2 Thursday November 9 2000 Time 1...

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

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:

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

View Full Document
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() {
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 8

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

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

View Full Document
Ask a homework question - tutors are online