In the bool end() function will the program know whether the sentinel is the beginning or end? Is there a check I can make to make sure it's reading the sentinel as the end?
#include "ring.h"
#include <stdlib.h>
#include <stdio.h>
struct node {
int item;
struct node *prev;
struct node *next;
};
typedef struct node node;
struct ring {
node *sentinel;
node *current;
};
ring *new_ring() {
ring *p;
node *n;
p = (ring *) malloc (sizeof(ring));
n = malloc(sizeof(node));
p->sentinel = n;
n->next = n;
n->prev = n;
return p;
}
void start(ring *r) {
r->current = r->sentinel;
}
bool end(ring *r) {
return r->current == r->sentinel;
}
void forward(ring *r) {
while (r->current != r->sentinel) {
r->current = r->current->next;
}
}