Guest User

Untitled

a guest
Oct 19th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. class node;
  2. class list
  3. {
  4. public:
  5. void insert(string f, string l, int a);
  6. int length();
  7.  
  8. private:
  9. node *head;
  10. int listlength;
  11. };
  12. class node
  13. {
  14. friend list;
  15. public:
  16. node(); // Null constructor
  17. ~node(); // Destructor
  18. void put(ostream &out); // Put
  19. bool operator == (const node &); // Equal
  20. bool operator < (const node &); // Less than
  21. private:
  22. string first, last;
  23. int age;
  24. node *next;
  25. };
  26.  
  27. while (!infile.eof())
  28. {
  29. infile >> first >> last >> age;
  30.  
  31. // Process if okay
  32.  
  33. if (infile.good())
  34. a.insert(first, last, age);
  35. };
  36.  
  37. void list::insert(string f, string l, int a)
  38. {
  39. node *temp1, *temp2 = head;
  40. temp1 = new node();
  41. temp1->first = f;
  42. temp1->last = l;
  43. temp1->age = a;
  44. temp1->next = NULL;
  45. if (listlength == 0)
  46. {
  47. temp1->next = head;
  48. }
  49. else
  50. while (temp2->next != NULL)
  51. {
  52. ;
  53. }
  54.  
  55. }
  56.  
  57. void sort(person b[], int count)
  58. {
  59. int i = 0, j = 0, indexofsmallest = i;
  60. person smallest = b[i];
  61.  
  62. for (i = 0; i < count; i++)
  63. {
  64. smallest = b[i];
  65. indexofsmallest = i;
  66.  
  67. for (j = i+1; j < count; j++)
  68. {
  69. if (b[j] < smallest)
  70. {
  71. smallest = b[j];
  72. indexofsmallest = j;
  73. }
  74. }
  75.  
  76. //cstdlib swap function
  77.  
  78. swap(b[i], b[indexofsmallest]);
  79. }
  80.  
  81. }
Add Comment
Please, Sign In to add comment