summaryrefslogtreecommitdiff
path: root/c/dataStructure/408/list/list.h
blob: 811c62d8a1927782ae642e6e2c27a520c2b714ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
 * In order to use one header file for both
 * sequence list and linked list, I used linked list style 
 * this may cause inconvenient when inplementing sequence list
 */

#ifndef _LIST_H
#define _LIST_H

#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>

#define MAX 50

typedef struct seq {
    int * data;
    int length;
    int maxSize;
} Seq;
typedef Seq * sqList;

typedef struct link {
    int elem;
    struct link * next;
} Link;
typedef Link * linkList;

typedef struct list {
    sqList sql;
    linkList lin;
} List;

/* initialize list
 * exit with code EXIT_FAILURE if initialize fail,
 * otherwise nothing return */
void initList(List * L);

/* return number of current elements
 * if list does not exist, return -1 */
int lengthList(List * L);

/* find location of the element
 * if element exists, return location
 * else return false */
bool locateElem(List * L, int * i, int e);

/* find element at given location
 * if location is bigger/smaller than length/0
 * return false
 * else return location */
bool getElem(List * L, int i, int * e);

/* insert element at given location
 * if location is bigger than length, insert at last
 * if location is 0 or negative, return false */
bool insertElem(List * L, int i, int e);

/* if location is bigger than length,
 * or is smaller than 1,
 * return false */
bool deleteElem(List * L, int i, int * e);
void printList (List * L);

/* check if list exist and have no element */
bool emptyList (List * L);
void deleteList(List * L);

#endif