I got it in my head to start writing some simple sorting algorithms a little while ago and decided that it would make my life easier to also write a swap function as well.
The problem is that while my swap algorithm seems to work just fine in the sort function, when I put it into it's own function it simply doesn't work. Here's the code: http://codepad.org/dxuC9vLE
#include <iostream>
usingnamespace std;
void myswap(int left, int right);
int main() {
int a = 1;
int b = 2;
cout << "a:" << a << ", b: " << b << endl;
myswap(a, b);
cout << "a:" << a << ", b: " << b;
return 0;
}
void myswap(int left, int right)
{
int storeleft = left;
int * sortpointer;
sortpointer = &left;
*sortpointer = right;
sortpointer = &right;
*sortpointer = storeleft;
}
When I run it through the debugger it looks like the values are being changed in a and b correctly but once the function exits the values go right back to their original declaration. Any ideas?