Convert upstream results to vector and sort problem!




My output from upstream program is as follow:

10 2 3 34 55 65 67 76 23
56 9 5 29 19 29 19 29 19
56 23 23 43 45 12 56 43 12
100 234 123 12 12 34 32 45 46
.
.

The my work is: Add the 10th column according to some criteria. Then sort based on the 10th column.

example as follow: add 10th column.

10 2 3 34 55 65 67 76 23 1
56 9 5 29 19 29 19 29 19 3
30 23 23 43 45 12 56 43 12 2
45 9 10 29 19 29 9 19 29 3
100 234 123 12 12 34 32 45 46 4

And should be sorted based on the last column (10th column)
example as follow: which is sorted

10 2 3 34 55 65 67 76 23 1
30 23 23 43 45 12 56 43 12 2
45 9 10 29 19 29 9 19 29 3
56 9 5 29 19 29 19 29 19 3
100 234 123 12 12 34 32 45 46 4

I tried with a vector!

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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <iostream>
#include <vector>
using namespace std;

int main () {

int main() {


std::vector<vector<int> > ph;
std::vector <int> p;

// here I have a program which will generate the matrix row by row

for (int j=0; j<=tr; j++) // this loop is from above program part and gives the value of nine verticies of triangle in each loop!

		
	// depending on the following if conditions the tenth vector is added
	if ((x1<20) && (z1<62))
			{
	p.push_back(x1);
	p.push_back(y1);
	p.push_back(z1);
	p.push_back(x2);
	p.push_back(y2);
	p.push_back(z2);
	p.push_back(x3);
	p.push_back(y3);
	p.push_back(z3);
	p.push_back(1);
	ph.push_back(p);
			}
	if ((20<=x1<=40)&& (z1<60))
	{
	p.push_back(x1);
	p.push_back(y1);
	p.push_back(z1);
	p.push_back(x2);
	p.push_back(y2);
	p.push_back(z2);
	p.push_back(x3);
	p.push_back(y3);
	p.push_back(z3);
		p.push_back(2);
		ph.push_back(p);
	}
		if((40<x1<60) && (z1<20))
				{
	p.push_back(x1);
	p.push_back(y1);
	p.push_back(z1);
	p.push_back(x2);
	p.push_back(y2);
	p.push_back(z2);
	p.push_back(x3);
	p.push_back(y3);
	p.push_back(z3);
    p.push_back (3);
	ph.push_back(p);
				}
	 else
	 {
	p.push_back(x1);
	p.push_back(y1);
	p.push_back(z1);
	p.push_back(x2);
	p.push_back(y2);
	p.push_back(z2);
	p.push_back(x3);
	p.push_back(y3);
	p.push_back(z3);
	p.push_back(4);
	ph.push_back(p);
	 }


	for(int i=0; i<ph.size()-1; i++)
	{

	     cout<<ph[i][0] << " " <<ph[i][1]<< " "<<ph[i][2]<<" "<<ph[i][3] << " " <<ph[i][4] <<" "<<ph[i][5]<<" "<<ph[i][6] << " " <<ph[i][7]<< " "<<ph[i][8]<<" "<<ph[i][9]<<endl;
        // cout <<ph[i][j]<<endl;

}
}




// I have no syntax error but, the loop doesn't work, it stops just after excuting the first loop!

What is the problem, would you please recommend!

Regards
Topic archived. No new replies allowed.