Hi I am developing a program that uses Breadth First Search to map a grid(2d array) out. Breadth First Search involves storing nodes in a stack and then exploring these nodes based on Breadth or level. I know how to create a vector array which I shall use as a stack. I need to know how to store array elements in the stack using the push_back()method. This is what I have so far.. vectorstack; //stack initialization. stack.push_back(array[1][1]) //store array element itself, not Value held in array! The value stored is not the array element, but the value which happens to be some integer x. Thanks for helping.
I got you point..First make a 2D vector like below:- Code: vector< vector<int>> stack Now, suppose a array with indexes 'i' and 'j'....i.e. array[j] value is to be stored in 'stack' we first create a 1D vector and store the indexes to that array like below:- Code: vector<int> p; p.push_back(i); p.push_back(j); Now, at the final step you store the 1D vector in 2D 'Stack' vector..like below:- Code: stack.push_back(temp); I hope it will help u...