simple function for making something in a .txt file ascending order

Hey I am making a program where it takes an occupation and their salary and calculating the average and the median of all the salaries from said occupation in a text file. How do I make a function to make it it order the occupation ascending order fro A-Z with their salaries ?
Anybody
use the bubblesort method, or use substrings and compare all the first letters of the occupation. capital A has the largest value and small z has the lowest
Can someone give me an example of how to sort using functions.


Waiter 12456.76
Programmer 47876.83
Dentist 111111.11
Accountant 38123.99


TO
Dentist $ 111111.11 
Programmer $ 47876.83 
Accountant $ 38123.99 
Waiter $ 12456.76
here is a tentative function:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
int Lrg_Pos(int st_pos, int l_pos)
{
  int i, n;
  i = st_pos;
  for(n = Lrg_TM + 1; n < l_pos - 1; n++)
	  if((salary[n]) > (salary[i]))
	  i = n;  
  return i;
}  	     

//st_pos is the start position where you wanna start the sorting and l_pos is the last
// then use a swap function

void swap (double &A,double &B)
{
  double Temp;
 
 A = Temp;
 B = A;
 Temp = B;
}
Last edited on
Topic archived. No new replies allowed.