I am running into problems when I am trying to display the elements which I store. Could anybody help with a code snippet doing this.
Also, in case like the above one how do you check memory storage. In other words how can one see the elements which are getting stored.
Any help will be appreciated.
Thanks.
Did you really want to push_back() here? This will add another item to newvec, giving you 4 items altogether. You reserved room for 3 items in the constructor for newvec.
Code:
newvec.push_back(int(n/10)); // Same here.
No need for int cast. n / 10 is already an int. BTW, you now have 5 items in newvec.
Code:
newvec.push_back(0);
You now have 6 items in newvec.
Code:
vliBuckets[t].push_back(newvec);
// Print information
for_each(vliBuckets.begin(), vliBuckets.end(), PrintBucketInfo );
}
The reason for the typedefs is that it increases readability and lessens typos.
Also, in case like the above one how do you check memory storage. In other words how can one see the elements which are getting stored.
This depends on your debugger. Or you have to write code to dump out the elements.
Thanks a lot for your reply. It really helped a lot.
I have my code giving the correct output. I have a function which calls these two functions(given below). Both of these functions at the time of returning are causing some memory problem (Unhandled exception error). If I comment out the statements which call these functions from the other function then it runs fine. So the problem is being caused by these functions. However, they are giving me the correct output.
You should post a small, compilable, and runnable version of a program that demonstrates the error. This way, all that is needed is for someone here to take your code, compile, run, and see what the error could be.
One thing I did notice -- you are using indices:
Code:
if(v[2] < counter)
{
list<vector<int> >& finlst = vliBuckets[v[1]%N];
v[1] = v[1]/N; // <-- Index used here
v[2] = v[2] + 1; // <-- Index used here too
v[0] = v[0];
finlst.push_back(v);
Are you sure there is really a v[0], v[1], and a v[2]? When you use operator [], STL does not check array boundaries. You should call V.size() to make sure that these items exist. For example
Code:
int ThisSize = V.size();
if ( ThisSize >= 3 ) { // Indices are OK }
else { // There is no such thing as v[2]!! }
Bookmarks