Hello All,
i am trying to tidy-up some code and i'm not completely sure how this can be done. What i have is this:
(This is some sort of psuedocode that i just wrote to explain the problem, not proper code)
void foo1(typeofList1 list1)
{
for (i = 0; i < list1.size) {
// iterate through listOfToys
for (j = 0; j < list1->listOfToys; j++) {
// do some stuff
}
}
}
void foo2(typeofList2 list2)
{
for (i = 0; i < list2.size) {
// iterate through listOfApples
for j = 0; j < list2->listOfApples; j++) {
// do some stuff
}
}
}
void genericFoo(genericList genList)
{
for (i = 0; i < genList.size) {
// How do i do the iteration here?
}
}
int main()
{
foo1(listOfItems1);
foo2(listOfItems2);
// this is what i need:, but problem with accessing the lists that they internally have.
genericFoo(listOfItems1);
genericFoo(listOfItems2);
return 0;
}
I plan on writing a single function to do the job of foo1 and foo2.
But, these two have different lists in them. So, i have a problem iterating the second list. I'm not sure how this can be solved. Can anyone please provide some hints/ideas? I hope i have explained the problem clearly
Thanks!