Hello, I was thinking of writing a program that writes all numbers of one combination in all orders,just for practice purpose :
(1,2,3):
1 2 3
1 1 2
1 2 3
and so on...
The program I wrote like this:
However, this program ends up in runtime error, would you please at least try to tell me, where is the problem?Code:#include <iostream> #include <vector> using namespace std ; template <class t> vector<t> assign(vector <t> array,short co,short kam) { vector <t> copy_array=array ; copy_array[kam]=array[co] ; return copy_array ; } template <class t> void comb(vector <t>array,short place,short size) //parameters -the array I am working on, itīs position, and itīs length { if (place==array.size()-1 ) //if the position is zero for (short x=0;x<size;x++) //then it is written on the screen cout<<array[x]<<endl ; for (short tocopy=0;tocopy<size;tocopy++) comb(assign(array,tocopy,place),place+1,size) ; //the very proccess of assigning all values } //clear int main() {vector <int> test ; test.push_back(1) ; test.push_back(2) ; test.push_back(3) ; short int size= test.size() ; comb(test,0,size) ; cin.get() ; return 0 ; }
Thanks
Garland



LinkBack URL
About LinkBacks


