mirror of https://gitlab.com/klmp200/LO27.git
188 lines
4.8 KiB
C
188 lines
4.8 KiB
C
/*
|
|
* This is a cellular automaton library
|
|
*
|
|
* Copyright (C) 2016-2017 Antoine BARTUCCIO, Jean POREE DE RIDDER
|
|
*
|
|
* Licensed under the MIT License,(the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
* hhttps://opensource.org/licenses/MIT
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
* SOFTWARE.
|
|
*
|
|
*/
|
|
|
|
#ifndef LIST_H
|
|
#define LIST_H
|
|
|
|
#include <CellElement.h>
|
|
|
|
#define SUCCESS 0
|
|
#define FAILURE 1
|
|
|
|
typedef struct ListElement ListElement;
|
|
struct ListElement {
|
|
cellElement *data;
|
|
ListElement *next;
|
|
ListElement *previous;
|
|
int pos;
|
|
};
|
|
|
|
typedef struct List {
|
|
ListElement *head;
|
|
ListElement *tail;
|
|
int size;
|
|
} List;
|
|
|
|
/**
|
|
* Create a new list
|
|
* @return List a pointer of list
|
|
*/
|
|
List * CreateList();
|
|
|
|
/**
|
|
* Insert an element at the begining of a list
|
|
* @param list pointer of a list
|
|
* @param data any type of data
|
|
* @return int status of the operation
|
|
*/
|
|
int unshift(List* list, cellElement* data);
|
|
|
|
/**
|
|
* Insert an element at the end of a list
|
|
* @param list pointer of a list
|
|
* @param data any type of data
|
|
* @return int status of the operation
|
|
*/
|
|
int push(List* list, cellElement* data);
|
|
|
|
/**
|
|
* Get an element in a given list
|
|
* @param list as a pointer
|
|
* @param nb the number of the element (can be negative)
|
|
* @return List an element
|
|
*/
|
|
ListElement * GetElement(List *list, int nb);
|
|
|
|
/**
|
|
* 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 int status of the operation
|
|
*/
|
|
int PopPtnList(List *list, ListElement *element);
|
|
|
|
/**
|
|
* Delete an element with a position in the list
|
|
* @param list as a pointer
|
|
* @param nb position of the element
|
|
* @return int status of the operation
|
|
*/
|
|
int RemoveElement(List *list, int nb);
|
|
|
|
/**
|
|
* Delete the first element of the list
|
|
* @param list as a pointer
|
|
* @return int status of the operation
|
|
*/
|
|
int shift(List *list);
|
|
|
|
/**
|
|
* Delete the last element of the list
|
|
* @param list as a pointer
|
|
* @return int status of the operation
|
|
*/
|
|
int pop(List *list);
|
|
|
|
/**
|
|
* Delete every elements in a list
|
|
* @param list as a pointer
|
|
* @return int status of the operation
|
|
*/
|
|
int DeleteListContent(List *list);
|
|
|
|
/**
|
|
* Free a list
|
|
* @param list as a pointer
|
|
* @return int status of the operation
|
|
*/
|
|
int FreeList(List *list);
|
|
|
|
/**
|
|
* 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 int 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 int 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 int 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 int 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 int 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 int 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 int status of the operation
|
|
*/
|
|
int InsertAfterPos(List *list, cellElement *data, int pos);
|
|
|
|
#endif /* LIST_H */
|