Category : C++ Source Code
Archive   : IDIOMS.ZIP
Filename : 7-2.C

 
Output of file : 7-2.C contained in archive : IDIOMS.ZIP
/* Copyright (c) 1992 by AT&T Bell Laboratories. */
/* Advanced C++ Programming Styles and Idioms */
/* James O. Coplien */
/* All rights reserved. */

#include

class Complex {
public:
int operator<(const Complex&);
};

ostream& operator<<(ostream&, const Complex&);
istream& operator>>(istream&, const Complex&);

template
void sort(S elements[], const int nelements) {
int flip = 0, sz = nelements - 1;
do {
for (int j = 0, flip = 0; j < sz; j++) {
if (elements[j] < elements[j+1]) {
S t = elements[j+1];
elements[j+1] = elements[j];
elements[j] = t;
flip++;
}
}
} while (flip);
}

int main() {
Complex cvec[12];
for (int i = 0; i < 12; i++) cin >> cvec[i];
sort(cvec, 12); // calls sort(Complex[], const int)
for (i = 0; i < 12; i++) cout << cvec[i] << endl;
return 0;
}


  3 Responses to “Category : C++ Source Code
Archive   : IDIOMS.ZIP
Filename : 7-2.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/