skitzFist

Untitled

Nov 13th, 2015
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. void sortList(int &antal, vector<Person> &familj){
  2. int max = antal - 1;
  3.  
  4. for (int i = 0; i < max; i++){
  5.  
  6. int nrLeft = max - i;
  7.  
  8. for (int j=0; j < nrLeft; j++){
  9.  
  10. familj[j].age;
  11.  
  12. if (familj[j].age > familj[j+1].age){
  13.  
  14. int temp = familj[j].age;
  15. string tempName = familj[j].name;
  16.  
  17. familj[j].age = familj[j+1].age;
  18. familj[j].name = familj[j+1].name;
  19.  
  20. familj[j].age = temp;
  21. familj[j].name = tempName;
  22. }
  23. }
  24. }
  25.  
  26. cout << "New list:\n\n";
  27. for (int i = 0; i < antal; i++){
  28. cout << "Name: " << familj[i].name << endl << "Age: " << familj[i].age << endl << endl;
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment