#ifndef _DLL_H_
#define _DLL_H_

/*! \file dll.h
    \brief A double linked list ADT.

    It is a ring list.
 */

/*! \brief A double linked list element. */
struct list_head {
   struct list_head *next, 
                    *prev;
};

/*! \brief Initializes this ADT.
 
 next and prev pointer point at head
 */
void list_init(struct list_head *head);

/*! \brief Inserts new entry after specified head. */
void list_add(struct list_head *new, struct list_head *head);

/*! \brief Inserts a new entry before the specified head. */
void list_add_tail(struct list_head *new, struct list_head *head);

/*! \brief Removes entry from list and reinitializes it.
  
  (next = prev = 0)
  \return entry removed entry
 */
struct list_head* list_del(struct list_head *entry);

/*! \brief Removes entry from one list and insert it after another's head. */
void list_move(struct list_head *entry, struct list_head *head);

/*! \brief Removes entry from one list and insert it before another's head. */
void list_move_tail(struct list_head *entry, struct list_head *head);

/*! \brief Tests whether a list is empty.
    \return 0, if list empty, else != 0
 */
int list_empty(struct list_head *head);

/*! \brief Gets n-tes element */
struct list_head* list_element(struct list_head *head, int element);

/*! \brief Frees all memory used by this ADT. 

    Including the memory used by head.
 */
void list_free(struct list_head *head);

#endif
