Hi, I am working on some practice problems for my class and I keep getting stuck on this problem. It is using linked list, I am bit stuck. The problem is to write a function int testloop (listnode *head) that checks to see whether the list 'head' contains a loop.
I just need help on how to approach the problem
#include <iostream>
using namespace std;
class listnode {
public:
listnode *next;
};
listnode *l[4];
void create_list();
int testloop(listnode *head);
int main()
{
int i;
cout << "creating lists......\n";
create_list(); // creating lists in *l[4]
for (i=0; i<4; i++) {
cout << "testing list " << i << " .....\n";
if (testloop(l[i]) == 1)
cout << " list " << i << " has a loop.\n";
else
cout << " list " << i << " does not have a loop.\n\n";
}
}