Skip to main content

Practice ยท 1 of 1

Build the Sentinel Deque

Implement a deque over a sentinel ring. The boilerplate declares: ``c typedef struct DNode { int value; struct DNode *prev, *next; } DNode; /* the caller owns the sentinel; init makes it self-linked */ void dq_init(DNode *s); void dq_push_front(DNode *s, int v); void dq_push_back(DNode *s, int v); int dq_pop_front(DNode *s, int *out); /* 0 ok, -1 empty */ int dq_pop_back(DNode *s, int *out); /* 0 ok, -1 empty */ size_t dq_len(const DNode *s); /* 1 if a forward walk and a backward walk see the same values reversed */ int dq_consistent(const DNode *s); ``

Difficulty: intermediate

Back to lesson: Practice: Doubly List & Deque Gym