Remember that dereferencing c on the left hand side (*c) will overwrite the pointer.
I think you need to realize that you ultimately want to swap values. The temp variable is supposed to save your first value so that when you put the second value where the first value was, you can still put the temp value where the second value was. Your function would work if temp weren't a pointer type.
That does exactly as I said.Code:void swap(element *foo, element *bar) { element temp = *foo; *foo = *bar; *bar = temp; }
If temp has to be a pointer, there is little point to it, because you have to new the extra space, and delete it before the function ends. The "extra space" part kinda has no way around it.