Code:
#include <stdio.h>
typedef struct node {
int value;
struct node *next;
} node;
int has_cycle(node *head)
{
// Your code goes here:
}
void test_has_cycle(void)
{
int i;
node nodes[25]; //enough to run our tests
for(i=0; i < sizeof(nodes)/sizeof(node); i++) {
nodes[i].next = 0;
nodes[i].value = 0;
}
nodes[0].next = &nodes[1];
nodes[1].next = &nodes[2];
nodes[2].next = &nodes[3];
printf(“Checking first list for cycles. There should be none,has_cycle
says it has %s cycle “,
has_cycle(&nodes[0])?”a”:”no”);
nodes[4].next = &nodes[5];
nodes[5].next = &nodes[6];
nodes[6].next = &nodes[7];
nodes[7].next = &nodes[8];
nodes[8].next = &nodes[9];
nodes[9].next = &nodes[10];
nodes[10].next = &nodes[4];
printf(“Checking second list for cycles. There should be acycle,
has_cycle says it has %s cycle “,
has_cycle(&nodes[4])?”a”:”no”);
nodes[11].next =
PayPal Gateway not configured
PayPal Gateway not configured