template<typename type>
void view(list<type> &lst)
{
int i = 0;
for (typename list<type>::iterator itr = lst.begin(); itr != lst.end(); itr++, i++) {
cout << i << ": " << *itr << "\n";
}
cout << "\n\n";
}
/*選択した要素数を指定の数字に変更*/
template<typename type,typename typeb>
void number_set(list<type> &lst, int &idx,typeb &n)
{
int i = 0;
typename list<type>::iterator it = lst.begin();
while (it != lst.end() && i != idx )
{
i++;
it++;
}
for (typename list<type>::iterator itr = lst.begin(); itr != lst.end(); itr++) {
if (itr == it) {
*itr = n;
}
}
view(lst);
}
void number(list<int> &lst, int idx, int &n)
{
cout << "int版\n";
int i = 0;
list<int>::iterator it = lst.begin();
while (it != lst.end() && i != idx)
{
i++;
it++;
}
for (list<int>::iterator itr = lst.begin(); itr != lst.end(); itr++)
{
if (itr == it)
{
*itr = n;
}
}
view(lst);
}
void number(list<double> &lst, int idx, double &n)
{
cout << "double版\n";
int i = 0;
list<double>::iterator it = lst.begin();
while (it != lst.end() && i != idx)
{
i++;
it++;
}
for (list<double>::iterator itr = lst.begin(); itr != lst.end(); itr++)
{
if (itr == it)
{
*itr = n;
}
}
view(lst);
}
int main() {
int p = 0;
//double p = 0.0;
//int n = 0;
double n = 0.0;
list<double> lst(10,1.5);
//list<int> lst(10, 1);
view(lst);
cout << "添え字を選択してください:";
cin >> p;
cout << "値:";
cin >> n;
//number_set(lst,p,n);
number(lst, p, n);
_getch();
return 0;
}