cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
General C++ Programming
Alphabetically sort a vector
Alphabetically sort a vector
Aug 27, 2012 at 7:57pm UTC
michaelscott88
(12)
I am trying to sort a vector and for some reason all it is doing is flipping the values. I looked over it several times and have been messing with it but with no success. Let me know if you see something wrong or something I may need to add, Thanks!
for(int x=0;x<4;x++){
temp=(*name)[x];
os<<temp;
os>>ida;
os>>fnamea;
os>>lnamea;
for(int y=x+1; y<4; y++){
temp=(*name)[y];
os<<temp;
os>>idb;
os>>fnameb;
os>>lnameb;
if(lnamea>lnameb){
(*name)[y]=(*name)[x];
(*name)[x]=temp;
temp=(*userid)[x];
(*userid)[x]=(*userid)[y];
(*userid)[x]=temp;
}
Aug 28, 2012 at 1:35am UTC
PanGalactic
(1658)
Can you show the full function signature so we have an idea about what the types are? And please put the code inside [code
] tags.
Topic archived. No new replies allowed.