C++ has a built in swap function

by qbguy (no login)

// swap algorithm example
#include <iostream>
#include <algorithm>
using namespace std;

typedef struct newtypet {
double a, b;
} newtypet;

newtypet old, neww;


int main () {

old.a = 10;
old.b = 20;
neww.a = 1;
neww.b = 2;
cout << old.a << endl;
cout << old.b << endl;
cout << neww.a << endl;
cout << neww.b << endl;
swap(old, neww);
cout << endl;
cout << old.a << endl;
cout << old.b << endl;
cout << neww.a << endl;
cout << neww.b << endl;
return 0;
}

Posted on Jun 27, 2008, 6:56 PM
from IP address 75.0.227.216

Respond to this message   

Return to Index


Response TitleAuthor and Date
Would be a lot easier to make in Qbasic........... on Jun 27
 The compiler translates to C++ which is why i mentioned C++'s swap functionqbguy on Jun 28