1
0
mirror of https://gitlab.com/klmp200/LO27.git synced 2024-11-16 20:23:20 +00:00
LO27/LibAutomaton/list.h

170 lines
4.0 KiB
C
Raw Normal View History

2016-12-10 01:28:10 +00:00
#ifndef LIST_H
#define LIST_H
2016-12-10 04:04:13 +00:00
#include <CellElement.h>
2016-12-10 01:28:10 +00:00
#define SUCCESS 0
#define FAILURE 1
typedef struct ListElement ListElement;
struct ListElement {
2016-12-11 00:25:35 +00:00
cellElement *data;
2016-12-10 01:28:10 +00:00
ListElement *next;
ListElement *previous;
2016-12-23 13:08:10 +00:00
int pos;
2016-12-10 01:28:10 +00:00
};
typedef struct List {
ListElement *head;
ListElement *tail;
int size;
} List;
2016-12-23 13:08:10 +00:00
/**
2016-12-10 01:28:10 +00:00
* Create a new list
* @return a pointer of list
*/
List * CreateList();
2016-12-23 13:08:10 +00:00
/**
2016-12-10 01:28:10 +00:00
* Insert an element at the begining of a list
* @param list pointer of a list
* @param data any type of data
* @param size size of the data
* @return status of the operation
*/
int unshift(List* list, cellElement* data);
2016-12-23 13:08:10 +00:00
/**
2016-12-10 01:28:10 +00:00
* Insert an element at the end of a list
* @param list pointer of a list
* @param data any type of data
* @param size size of the data
* @return status of the operation
*/
2016-12-10 04:04:13 +00:00
int push(List* list, cellElement* data);
2016-12-10 01:28:10 +00:00
2016-12-23 13:08:10 +00:00
/**
2016-12-10 01:28:10 +00:00
* Get an element in a given list
* @param list as a pointer
* @param nb the number of the element (can be negative)
* @return an element
*/
ListElement * GetElement(List *list, int nb);
2016-12-23 13:08:10 +00:00
/**
2016-12-10 01:28:10 +00:00
* Delete an element with a pointer of element in the list
* @param list as a pointer
* @param element of the list as a pointer
* @return status of the operation
*/
int PopPtnList(List *list, ListElement *element);
2016-12-23 13:08:10 +00:00
/**
2016-12-10 01:28:10 +00:00
* Delete an element with a position in the list
* @param list as a pointer
* @param position of the element
* @return status of the operation
*/
int RemoveElement(List *list, int nb);
2016-12-23 13:08:10 +00:00
/**
2016-12-10 01:28:10 +00:00
* Delete the first element of the list
* @param list as a pointer
* @return status of the operation
*/
int shift(List *list);
2016-12-23 13:08:10 +00:00
/**
2016-12-10 01:28:10 +00:00
* Delete the last element of the list
* @param list as a pointer
* @return status of the operation
*/
int pop(List *list);
2016-12-23 13:08:10 +00:00
/**
2016-12-10 01:28:10 +00:00
* Delete every elements in a list
* @param list as a pointer
* @return status of the operation
*/
int DeleteListContent(List *list);
2016-12-23 13:08:10 +00:00
/**
2016-12-10 01:28:10 +00:00
* Free a list
* @param list as a pointer
* @return status of the operation
*/
int FreeList(List *list);
2016-12-23 13:08:10 +00:00
/**
* Find the first element with the given pos value
* @param list as a pointer
* @param pos the pos value to find
* @return ListElement the found element can return NULL
*/
ListElement * GetElementPos(List *List, int pos);
/**
* Delete the first element of a list with the given pos
* @param list as a pointer
* @param pos pos value of the element
* @return status of the operation
*/
int RemoveElementPos(List *list, int pos);
/**
* Insert an element in a list before the given element
* @param list as a pointer
* @param eli an element to insert
* @param elp the previous element in the list
* @return status of the operation
*/
int InsertBeforeElement(List *list, ListElement *eli, ListElement *elp);
/**
* Insert an element in a list after the given element
* @param list as a pointer
* @param eli an element to insert
* @param elb the before element in the list
* @return status of the operation
*/
int InsertAfterElement(List *list, ListElement *eli, ListElement *elb);
/**
* Insert an element in a list before the given position
* @param list as a pointer
* @param data cellElement to insert
* @param nb the position in list to find
* @return status of the operation
*/
int InsertBefore(List *list, cellElement *data, int nb);
/**
* Insert an element in a list after the given position
* @param list as a pointer
* @param data cellElement to insert
* @param nb the position in list to find
* @return status of the operation
*/
int InsertAfter(List *list, cellElement *data, int nb);
/**
* Insert an element in a list before the first element with the given pos
* @param list as a pointer
* @param data cellElement to insert
* @param pos the first pos in list to find
* @return status of the operation
*/
int InsertBeforePos(List *list, cellElement *data, int pos);
/**
* Insert an element in a list after the first element with the given pos
* @param list as a pointer
* @param data cellElement to insert
* @param pos the first pos in list to find
* @return status of the operation
*/
int InsertAfterPos(List *list, cellElement *data, int pos);
2016-12-10 01:28:10 +00:00
#endif /* LIST_H */