両端キューを破棄しようとしていますが、どういうわけかポインターで失敗します。次のコードを作成しました (deque は、deque の最初の要素を指すポインターへのポインターです)。DequeItem は、フィールド next (次の要素へのポインター) と data (void *) を持つ構造体です。
void deque_destroy(DequeItem **deque) {
DequeItem *temp;
DequeItem *item;
for (item = *deque; item != NULL; item = temp) {
printf("%d", *((int*)((item)->data)));
temp = item->next;
free(item);
}
}
構造体宣言は次のとおりです。
struct DequeItem {
void *data; // Data stored in the deque item
struct DequeItem *previous; // Pointer to the previous DequeItem in the ring
struct DequeItem *next; // Pointer to the next DequeItem in the ring
};
typedef struct DequeItem DequeItem;