sort structures
C / C++ / MFC
4
Posts
4
Posters
0
Views
1
Watching
-
= per[x+1]; per[x+1] = *temp; } } } the results are not right, duplicated entries and other oddness, whats wrong?
kerrywes wrote:
per[x+1] = *temp;
that doesn't seem right. shouldn't it be "per[x+1]=temp;" i assume per is an array of pointers to PERSONs Cleek | Image Toolkits | Thumbnail maker
-
= per[x+1]; per[x+1] = *temp; } } } the results are not right, duplicated entries and other oddness, whats wrong?gets just a pointer but then per[x] = per[x+1] does a copy, destroying the original data. You need to force copies for each of the swap operations. You also need to make temp a value, not a pointer. temp = per[x]; per[x] = per[x+1]; per[x+1] = temp; Ultimately, this realy doesn't do a sort, though. It just does a single pass through the array. Look up bubble sort to learn how to do a very basic sort. (Generally, using qsort, or some version thereof, would be better.) Anyone who thinks he has a better idea of what's good for people than people do is a swine. - P.J. O'Rourke
-
= per[x+1]; per[x+1] = *temp; } } } the results are not right, duplicated entries and other oddness, whats wrong?
kerrywes wrote:
= per[x+1]; 5. per[x+1] = *temp; 6. }but replace the content of that ! must change to= per[x+1]; per[x+1] = *temp; }but in this case you have a problem that the temp is pointer, you most declere it asPERSON temp;
Iman Ghasrfakhri -- modified at 1:12 Sunday 30th October, 2005