what's wrong with my pushback

i keep getting this error message

lab38.cpp:27: error: request for member `push_back' in `*(&itr)->__gnu_cxx::__normal_iterator<_Iterator, _Container>::operator-> [with _Iterator = uint*, _Container = std::vector<uint, std::allocator<uint> >]()', which is of non-class type `unsigned int'
*** Error code 1
make: Fatal error: Command failed for target `lab38.o'

here's my 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
#include <iostream>
#include <vector>
#include <cmath>
#include <d_matrix.h>
#include <algorithm>

void bucketSort(vector<uint>& v, uint numDigits)
{
	vector<vector<uint> > mat;
	vector<vector<uint> >::iterator rowitr;
	vector<uint>::iterator itr;
	mat.resize(10);
	for(int i = 0; i < numDigits ;++i)
	{
		int factor = 1;
		int j = v[i]/factor % 10;
		for(rowitr = mat.begin(); rowitr < mat.end();++rowitr)
			for(itr = rowitr->begin(); itr < rowitr->end();++itr)
			{
				rowitr + j;
				itr->push_back(v[i]);
			}
		v.back();
		v.pop_back();
		factor*=10;
	}
}

can anybody help?
the problem seems to lie in line 21 with itr->push_back(v[i]);
Last edited on
line 20: statement has no effect.
line 21: see declaration of `itr', dereferencing it yields an integer, not a vector, ¿what's that supposed to do?
the program looks at the one's place of a vector and puts it into buckets,after that it puts them back into the vector ,then it looks at the 10s place ant puts those into a bucket and puts it back into the vector so on. the buckets are a vector of vector going from 0-9
it looks like so
v=53,72,42,11,31
pass 1 pass2
0| 0|
1| 11 31 1| 11
2| 42 72 2|
3|53 3| 31
4| 4| 42

pass 2
0|
1| 11
2|
3| 31
4| 42
5| 53
6|
7| 72
v=11,31,42,53,72

also i thought rowitr + j would increment through rowitr j times. how would i get it to do so?
Last edited on
> the program looks at the one's place of a vector and puts it into buckets
the program traverse the vector and puts each element in a bucket according to the last digit.

However I don't see anywhere in your code where you fill `mat', the bucket list.

1
2
3
4
5
for(size_t K=0; K<v.size(); ++K){
	int number = v[K];
	int digit = number % 10;
	bucket[digit].push_back(number);
}



> after that it puts them back into the vector
¿put them back how? ¿in the order of traversal?
1
2
3
		for(rowitr = bucket.begin(); rowitr < bucket.end();++rowitr)
			for(itr = rowitr->begin(); itr < rowitr->end();++itr)
				v.push_back( *it );



> then it looks at the 10s place ant puts those into a bucket and puts it back into the vector so on
the it looks the next digit and repeat the operation.

1
2
3
4
5
6
7
8
9
for(int i = 0, factor=1; i < numDigits ;++i, factor*=10){
	std::vector< std::vector<uint> > bucket; //limit the scope, you may also declare it outside and do bucket.clear()
	//puts each element of the vector in a bucket according to the digit.
	//int digit = number/factor % 10;

	v.clear(); //I suppose that you don't want duplicates

	//puts the element of the bucket them back into the vector
}



> also i thought rowitr + j would increment through rowitr j times. how would i get it to do so?
you never catch the result value, I doubt that you want to modify `rowitr' as that would affect the outer loop.
So foo = rowitr+j; and then use `foo'

Now, `rowitr+j' means `j' rows after the one that `rowitr' points to.
Topic archived. No new replies allowed.