I’m trying to do a loop for this part:
insert_front(&list,name[0]);
insert_front(&list,name[1]);
insert_front(&list,name[2]);
but, i can’t figure out which should be used as a limiter, which should stop the loop for going and how it will change the name[] perimeters.
Here’s the whole code:
#include "list.h"
#include "string"
using namespace std;
int main(){
cout<<"What is your name \n";
string name;
getline(cin,name);
Node *list;
list = new_list();
insert_front(&list,name[0]);
insert_front(&list,name[1]);
insert_front(&list,name[2]);
}
print_list(list);
delete_list(&list);
print_list(list);
return 0;
}
Iterator version (C++03):
Foreach version (C++11):
Index version (C++03):
Foreach version (C++03 with Boost):
I’m not so sure on the C++11 foreach version.
There’s probably also a reasonable way to use std::copy or std::transform if your hand-coded list has iterators.