1
0
mirror of https://gitlab.com/klmp200/LO27.git synced 2024-11-26 04:14:15 +00:00
LO27/LibMatrix/list.h

206 lines
5.3 KiB
C
Raw Permalink Normal View History

2016-12-29 15:09:39 +00:00
/*
* 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.
*
*/
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
2016-12-31 19:19:49 +00:00
/**
* One row or column of a Matrix
*
* @param data a pointer on the first cellElement of the column/row
* @param next a pointer on the next col/row of the Matrix
* @param previous a pointer on the previous col/row of the Matrix
* @param pos the index of the col/row in the Matrix
*
*/
2016-12-10 01:28:10 +00:00
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
};
2016-12-31 19:19:49 +00:00
/**
* The list of rows or columns of a Matrix
*
* @param head a pointer on the first col/row of the Matrix
* @param tail a pointer on the last col/row of the Matrix
* @param size the number of non void cols/rows
*
*/
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
2016-12-31 19:19:49 +00:00
*
2016-12-28 16:22:02 +00:00
* @return List a pointer of list
2016-12-10 01:28:10 +00:00
*/
2017-01-01 15:35:34 +00:00
List * createList();
2016-12-10 01:28:10 +00:00
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
2016-12-28 16:22:02 +00:00
* @return int status of the operation
2016-12-10 01:28:10 +00:00
*/
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
2016-12-28 16:22:02 +00:00
* @return int status of the operation
2016-12-10 01:28:10 +00:00
*/
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)
2016-12-28 16:22:02 +00:00
* @return List an element
2016-12-10 01:28:10 +00:00
*/
2017-01-01 15:35:34 +00:00
ListElement * getElement(List *list, int nb);
2016-12-10 01:28:10 +00:00
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
2016-12-28 16:22:02 +00:00
* @return int status of the operation
2016-12-10 01:28:10 +00:00
*/
2017-01-01 15:35:34 +00:00
int popPtnList(List *list, ListElement *element);
2016-12-10 01:28:10 +00:00
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
2016-12-28 16:22:02 +00:00
* @param nb position of the element
* @return int status of the operation
2016-12-10 01:28:10 +00:00
*/
2017-01-01 15:35:34 +00:00
int removeElement(List *list, int nb);
2016-12-10 01:28:10 +00:00
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
2016-12-28 16:22:02 +00:00
* @return int status of the operation
2016-12-10 01:28:10 +00:00
*/
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
2016-12-28 16:22:02 +00:00
* @return int status of the operation
2016-12-10 01:28:10 +00:00
*/
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
2016-12-28 16:22:02 +00:00
* @return int status of the operation
2016-12-10 01:28:10 +00:00
*/
2017-01-01 15:35:34 +00:00
int deleteListContent(List *list);
2016-12-10 01:28:10 +00:00
2016-12-23 13:08:10 +00:00
/**
2016-12-10 01:28:10 +00:00
* Free a list
* @param list as a pointer
2016-12-28 16:22:02 +00:00
* @return int status of the operation
2016-12-10 01:28:10 +00:00
*/
2017-01-01 15:35:34 +00:00
int freeList(List *list);
2016-12-10 01:28:10 +00:00
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
*/
2017-01-01 15:35:34 +00:00
ListElement * getElementPos(List *list, int pos);
2016-12-23 13:08:10 +00:00
/**
* Delete the first element of a list with the given pos
* @param list as a pointer
* @param pos pos value of the element
2016-12-28 16:22:02 +00:00
* @return int status of the operation
2016-12-23 13:08:10 +00:00
*/
2017-01-01 15:35:34 +00:00
int removeElementPos(List *list, int pos);
2016-12-23 13:08:10 +00:00
/**
* 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
2016-12-28 16:22:02 +00:00
* @return int status of the operation
2016-12-23 13:08:10 +00:00
*/
2017-01-01 15:35:34 +00:00
int insertBeforeElement(List *list, ListElement *eli, ListElement *elp);
2016-12-23 13:08:10 +00:00
/**
* 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
2016-12-28 16:22:02 +00:00
* @return int status of the operation
2016-12-23 13:08:10 +00:00
*/
2017-01-01 15:35:34 +00:00
int insertAfterElement(List *list, ListElement *eli, ListElement *elb);
2016-12-23 13:08:10 +00:00
/**
* 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
2016-12-28 16:22:02 +00:00
* @return int status of the operation
2016-12-23 13:08:10 +00:00
*/
2017-01-01 15:35:34 +00:00
int insertBefore(List *list, cellElement *data, int nb);
2016-12-23 13:08:10 +00:00
/**
* 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
2016-12-28 16:22:02 +00:00
* @return int status of the operation
2016-12-23 13:08:10 +00:00
*/
2017-01-01 15:35:34 +00:00
int insertAfter(List *list, cellElement *data, int nb);
2016-12-23 13:08:10 +00:00
/**
* 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
2016-12-28 16:22:02 +00:00
* @return int status of the operation
2016-12-23 13:08:10 +00:00
*/
2017-01-01 15:35:34 +00:00
int insertBeforePos(List *list, cellElement *data, int pos);
2016-12-23 13:08:10 +00:00
/**
* 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
2016-12-28 16:22:02 +00:00
* @return int status of the operation
2016-12-23 13:08:10 +00:00
*/
2017-01-01 15:35:34 +00:00
int insertAfterPos(List *list, cellElement *data, int pos);
2016-12-23 13:08:10 +00:00
2016-12-10 01:28:10 +00:00
#endif /* LIST_H */