-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.c
50 lines (36 loc) · 1.13 KB
/
example.c
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
#include "DoublyLinkedList.h"
int main(int argc, char** argv)
{
// Create a linked-list
DoublyLinkedList *list = createDoublyLinkedList();
// Insert some data
insertAtBeginning(list, 1);
insertAtBeginning(list, 2);
insertAtBeginning(list, 3);
insertAtEnd(list, 4);
insertAtEnd(list, 5);
insertAtEnd(list, 6);
// Print the list
printList(list);
// Print the list in reverse order
printListReverse(list);
// Reverse the list
reverseList(list);
// Print the list
printList(list);
// Get the size of the list
printf("Size: %d\n", getSize(list));
// Get the data at the given index
printf("Data at index 2: %d\n", getDataAtIndex(list, 2));
// Get the index of the given data
printf("Index of 5: %d\n", getIndex(list, 5));
// Check if the list is empty
printf("Is empty: %s\n", isEmpty(list) ? "true" : "false");
// Delete the first node
deleteFirst(list);
// Delete the last node
deleteLast(list);
// Delete the node at the given index
deleteAtIndex(list, 2);
return 0;
}