Advertisement
Guest User

Untitled

a guest
Oct 19th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.49 KB | None | 0 0
  1. /**
  2.  *  Header file for a linked list in C
  3.  *
  4.  * @authors:        Michael Denzel
  5.  * @creation_date:  2016-09-05
  6.  * @contact:        m.denzel@cs.bham.ac.uk
  7.  */
  8.  
  9. #ifndef LINKEDLIST_H
  10. #define LINKEDLIST_H
  11.  
  12. // --- Data structures ---
  13.  
  14. // TODO: Define additional data structures here when you need them.
  15.  
  16. typedef struct list{
  17.   // TODO: define your list structure here!
  18.     int value;
  19.     struct list* next;
  20. } list;
  21.  
  22. // --- Functions ---
  23.  
  24. /*
  25.  * Function to initialize a new list
  26.  *
  27.  * #Argument
  28.  * * `l`    - The list to be initialized
  29.  *
  30.  */
  31. void init(list * l);
  32.  
  33. /*
  34.  * Function to free a list when it is not needed anymore
  35.  *
  36.  * #Argument
  37.  * * `l`    - The list to be destroyed
  38.  *
  39.  */
  40. void destroy(list * l);
  41.  
  42. /*
  43.  * Function to get `data` of element number `index`.
  44.  *
  45.  * #Arguments
  46.  * * `l`    - The list to be modified
  47.  * * `index`   - the index of the searched element.
  48.  *
  49.  * #Return
  50.  * Returns the `data` field of the element or -1 in case of errors.
  51.  *
  52.  */
  53. int get(list * l, unsigned int index);
  54.  
  55. /*
  56.  * Function to prepend a new element to the list.
  57.  *
  58.  * #Arguments
  59.  * * `l`    - The list to be modified
  60.  * * `data`   - the integer to add to the front of the linkedlist.
  61.  *
  62.  * #Return
  63.  * Returns 0 for successful termination and -1 in case of errors.
  64.  *
  65.  */
  66. int prepend(list * l, int data);
  67.  
  68. /*
  69.  * Function to append a new element to the list.
  70.  *
  71.  * #Arguments
  72.  * * `l`    - The list to be modified
  73.  * * `data`   - the integer to add to the back of the linkedlist.
  74.  *
  75.  * #Return
  76.  * Returns 0 for successful termination and -1 in case of errors.
  77.  *
  78.  */
  79. int append(list * l, int data);
  80.  
  81. /*
  82.  * Function to insert a new element to the list.
  83.  *
  84.  * #Arguments
  85.  * * `l`    - The list to be modified
  86.  * * `index`  - the index after which the new element should be inserted.
  87.  * * `data`   - the integer which should be stored in the new element.
  88.  *
  89.  * #Return
  90.  * Returns 0 for successful termination and -1 in case of errors.
  91.  *
  92.  */
  93. int insert(list * l, unsigned int index, int data);
  94.  
  95. /*
  96.  * Function to delete an existing element from the list.
  97.  *
  98.  * #Arguments
  99.  * * `l`    - The list to be modified
  100.  * * `index`   - the index of the element to remove from the linkedlist.
  101.  *
  102.  * #Return
  103.  * Returns 0 for successful termination and -1 in case of errors.
  104.  *
  105.  */
  106. int remove_element(list * l, unsigned int index);
  107.  
  108. /*
  109.  * Function to print all elements of the list.
  110.  *
  111.  * #Arguments
  112.  * * `l`      - the list to print.
  113.  */
  114. void print_list(list * l);
  115.  
  116. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement