-
Notifications
You must be signed in to change notification settings - Fork 0
/
DoublyLinkedList.h
152 lines (131 loc) · 2.61 KB
/
DoublyLinkedList.h
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#ifndef _DOUBLY_LINKED_LIST_H_
#define _DOUBLY_LINKED_LIST_H_
#include <stdio.h> // printf, scanf
#include <stdlib.h> // malloc, free
#include <stdbool.h> // bool, true, false
typedef struct Node {
int data;
struct Node *next;
struct Node *prev;
} Node;
typedef struct DoublyLinkedList {
Node *head;
Node *tail;
int size;
} DoublyLinkedList;
/**
* @brief Create a new node
*
* @param data
* @return Node*
*/
Node* createNode(int data);
/**
* @brief Create a new doubly linked list
*
* @return DoublyLinkedList*
*/
DoublyLinkedList* createDoublyLinkedList();
/**
* @brief Insert a new node at the end of the list
*
* @param list
* @param data
*/
void insertAtEnd(DoublyLinkedList *list, int data);
/**
* @brief Insert a new node at the beginning of the list
*
* @param list
* @param data
*/
void insertAtBeginning(DoublyLinkedList *list, int data);
/**
* @brief Insert a new node at the given index
*
* @param list
* @param data
* @param index
*/
void insertAtIndex(DoublyLinkedList *list, int data, int index);
/**
* @brief Delete the first node of the list
*
* @param list
*/
void deleteFirst(DoublyLinkedList *list);
/**
* @brief Delete the last node of the list
*
* @param list
*/
void deleteLast(DoublyLinkedList *list);
/**
* @brief Delete the node at the given index
*
* @param list
* @param index
*/
void deleteAtIndex(DoublyLinkedList *list, int index);
/**
* @brief Print the list
*
* @param list
*/
void printList(DoublyLinkedList *list);
/**
* @brief Reverse the list
*
* @param list
*/
void reverseList(DoublyLinkedList *list);
/**
* @brief Print the list in reverse order
*
* @param list
*/
void printListReverse(DoublyLinkedList *list);
/**
* @brief Get the size of the list
*
* @param list
* @return int
*/
int getSize(DoublyLinkedList *list);
/**
* @brief Get the data at the given index
*
* @param list
* @param index
* @return int
*/
int getDataAtIndex(DoublyLinkedList *list, int index);
/**
* @brief Get the index of the given data
*
* @param list
* @param data
* @return int
*/
int getIndex(DoublyLinkedList *list, int data);
/**
* @brief Check if the list is empty
*
* @param list
* @return true
* @return false
*/
bool isEmpty(DoublyLinkedList *list);
/**
* @brief Clear the list
*
* @param list
*/
void clear(DoublyLinkedList *list);
/**
* @brief Free the list
*
* @param list
*/
void freeList(DoublyLinkedList *list);
#endif