how to store the values in forward list in the last(like insertion in the back) if we take data of forward list from the user. i tried but getting error. please help.
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int a,n,i,k=0;
cin>>n;
forward_list<int>l;
for(i=0;i<5;i++)
{
cin>>a;
if(i==0)
{
l.push_front(a);
}
else
{
l.insert_after(l.begin()+k,a);
k++;
}
}
for(auto&it:l)
cout<<it<<"->";
return 0;
}
