2009
Jul
28
Plagiarizing quicksort?
Posted by David Zaslavsky onI found an interesting tidbit in one of Princeton’s old academic integrity handbooks that I wanted to share before throwing it out.
They’re trying to demonstrate plagiarism in something other than the usual humanities-paper context. Which is a good goal, I suppose, but the execution leaves something to be desired. Here’s the “original” implementation of quicksort, from Bob Sedgewick’s Algorithms in C, as reproduced in the handbook:
quicksort (int a[], int l, int r)
{
int v, i, j, t;
if (r > l)
{
v = a[r]; i = l-1; j = r;
for (;;)
{
while (a[++i] < v) ;
while (a[–j] > v);
if (i >= j) break;
t = a[i]; a[i] = a[r]; a[r] = t;
}
t = a[i]; a[i] = a[r]; a[r] = t
quicksort (a, l, i-1);
quicksort (a, i+1, r);
}
}
And here’s their plagiarized example:
#define Swap(A,B) {temp=(A); (A)=(B); (B)=(A); }
void mysort (const int * data, int x, int y) {
int temp;
while (y > x) {
int pivot = data[y];
int i = x-1;
int j = r;
while (1) {
while (data [++i] < pivot) { /*do nothing*/ }
while (data [–j] > pivot) { /*do nothing*/ }
if (i >= j) break;
swap (data [i], data [y];
}
swap (data …