summaryrefslogtreecommitdiff
path: root/c/dataStructure/408/list/list.h
diff options
context:
space:
mode:
authorgarhve <git@garhve.com>2022-12-05 19:43:39 +0800
committergarhve <git@garhve.com>2022-12-05 19:43:39 +0800
commitc6bc541ab58363d783e60a007e80e9bf9e231fda (patch)
treea59c7ed0d05225c5876f3e5e919d4f6ed0c447ff /c/dataStructure/408/list/list.h
initialize
Diffstat (limited to 'c/dataStructure/408/list/list.h')
-rwxr-xr-xc/dataStructure/408/list/list.h69
1 files changed, 69 insertions, 0 deletions
diff --git a/c/dataStructure/408/list/list.h b/c/dataStructure/408/list/list.h
new file mode 100755
index 0000000..811c62d
--- /dev/null
+++ b/c/dataStructure/408/list/list.h
@@ -0,0 +1,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