M
Michael
Hi,
I could use vector to get an array to random_shuffle it. Is it possible
to define an array to random_shuffle it? I tried but it did not work.
Can I use array[] instead of vector to use algorithm?
Could you please help me out? Thanks.
Michael
1. vector (works)
#include <iostream>
#include <vector>
#include <algorithm>
using std::cout;
void show_val(int x)
{
cout<<x<<endl;
}
int main()
{
vector<int> a;
for (int i=1; i<11;i++)
a.push_back(i);
random_shuffle(a.begin(), a.end());
for_each(a.begin(), a.end(), show_val);
return 0;
}
2. array (not work)
#include <iostream>
#include <vector>
#include <algorithm>
using std::cout;
void show_val(int x)
{
cout<<x<<endl;
}
int main()
{
int a [100];
for (int i=0; i<100;i++)
a=i+1;
random_shuffle(a.begin(), a.end());
for_each(a.begin(), a.end(), show_val);
return 0;
}
I could use vector to get an array to random_shuffle it. Is it possible
to define an array to random_shuffle it? I tried but it did not work.
Can I use array[] instead of vector to use algorithm?
Could you please help me out? Thanks.
Michael
1. vector (works)
#include <iostream>
#include <vector>
#include <algorithm>
using std::cout;
void show_val(int x)
{
cout<<x<<endl;
}
int main()
{
vector<int> a;
for (int i=1; i<11;i++)
a.push_back(i);
random_shuffle(a.begin(), a.end());
for_each(a.begin(), a.end(), show_val);
return 0;
}
2. array (not work)
#include <iostream>
#include <vector>
#include <algorithm>
using std::cout;
void show_val(int x)
{
cout<<x<<endl;
}
int main()
{
int a [100];
for (int i=0; i<100;i++)
a=i+1;
random_shuffle(a.begin(), a.end());
for_each(a.begin(), a.end(), show_val);
return 0;
}