urgent-please help by sorting

I will sort a vector consisting of floats in ascending order. I can find the smallest elements of them. no problem by sorting. but i want to know which one was the smallest in my original vector.

for example my floats are: 3 7 13 2 24 64
after sorting it will seem so: 2 3 7 13 24 64

I want to know that 4th member is the smallest (2). That means the smallest number was 4th member of my original vector.How can i hold this value also, i mean how can i say that it is 4th element in my algorithm?
Last edited on
Please show us your code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
float mainpress,maintemp,mainpow,allvariables,diff,mindist=100000;
	vector<float> list;
	vector<float>presslist;
	vector<float>templist;
	vector<float>powerlist;
	vector<float>difflist;
	ifstream myfile ("example.txt");
	ofstream yourfile;
	yourfile.open("powerwrtnearest.txt");
	ofstream secndfile;
	thrdfile.open("thrdnearest.txt");
	int j,i,neighbour;
	for( j=0;j<7500;j++)
		{	myfile >> allvariables;
	list.push_back(allvariables);}//reading datas from file and sending to vector
	for( j=0;j<7500;j++)
		{	int div,mod=j%3;
			div=j/3+1;
			if(mod==0){
				maintemp=list.at(j) ;
				templist.push_back(maintemp) ;	}		
			if(mod==1){
				mainpress = list.at(j) ;	
				presslist.push_back(mainpress);}
			if(mod==2){
				mainpow= list.at(j);
				powerlist.push_back (mainpow);}}//sorting datas as power temp and pressure
		for(i=0;i<2500;i++){
			for(j=0;j<2500;j++){
				diff=sqrt(((templist.at(i)-templist.at(j))*(templist.at(i)-templist.at(j)))+((presslist.at(i)-presslist.at(j))*(presslist.at(i)-presslist.at(j))));
				if(i==j)
					diff=100000;
				difflist.push_back(diff);}//findig distances and listing them
			
			difflist.clear();}


I need to find 3rd smallest diff. then i should print the power of this diff.
Topic archived. No new replies allowed.