-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlistAsLinkedList.h
executable file
·135 lines (118 loc) · 4.43 KB
/
listAsLinkedList.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
/**
* ===========================================================
* Name:
* Section:
* Project: Implementation of Linked List Library
* Purpose: List ADT as linked list
* ===========================================================
*/
#ifndef LISTASLINKEDLIST_H
#define LISTASLINKEDLIST_H
#include <stdbool.h>
// Define a node of the linked list
typedef struct node {
double data;
struct node* next;
} Node;
// Define the type (meta-data) that manages the linked list of nodes
typedef struct {
Node* head;
Node* tail;
int numberOfElements;
} LinkedList;
// Functions that manipulate a linked list
/** createLinkedList()
* @brief - initializes the linked list structure
* @return - pointer to linked list
* @pre - nothing
* @post - new empty linked list returned
*/
LinkedList* createLinkedList();
/** deleteLinkedList(()
* @brief - deletes linked list, freeing all memory used
* @param list - a ptr to the linked list structure
* @pre - unmodified linked list
* @post - the linked list is erased
*/
void deleteLinkedList(LinkedList* list);
/** appendElementLinkedList()
* @brief - addes a new element to the end of the linked list
* @param list - a ptr to the linked list structure
* @param element - the value to append to the list
* @pre - linked list before element added
* @post - linked list one element longer
*/
void appendElementLinkedList(LinkedList* list, double element);
/** lengthOfLinkedList()
* @brief - returns the size of the linked list
* @param list - a ptr to the linked structure
* @return - number of items in the linked list
* @pre - linked list unmodified
* @post - linked list unmodified; size of linked list returned
*/
int lengthOfLinkedList(LinkedList* list);
/** printLinkedList()
* @brief - outputs the linked list to the console
* @param list - the linked list structure
* @pre - linked list unmodified
* @post - linked list unmodified; linked list elements printed
*/
void printLinkedList(LinkedList* list);
/** getElementLinkedList()
* @brief - retrieves element at a given position
* @param list - a ptr to the linked list structure
* @param position - index of value requested
* @return - value at 'position', -1 on failure
* @pre - unmodified linked list
* @post - unmodified linked list; value at 'position' returned
*/
double getElementLinkedList(LinkedList* list, int position);
/** deleteElementLinkedList()
* @brief - deletes element at a given position
* @param list - a ptr to the linked list structure
* @param position - index of value to delete
* @pre - unmodified linked list
* @post - modified linked list; value at 'position' removed
*/
void deleteElementLinkedList(LinkedList* list, int position);
/** insertElementLinkedList()
* @brief - adds element at a given position
* @param list - a ptr to the linked list structure
* @param position - index of value to add
* @param element - value to be added
* @pre - unmodified linked list
* @post - modified linked list; value add at 'position'
*/
void insertElementLinkedList(LinkedList* list, int position, double element);
/** changeElementLinkedList()
* @brief - changes element at a given position
* @param list - a ptr to the linked list structure
* @param position - index of value to add
* @param element - new value
* @pre - unmodified linked list
* @post - modified linked list; value changed at 'position'
*/
void changeElementLinkedList(LinkedList* list, int position, double newElement);
/** findElementLinkedList()
* @brief - finds the postion of a given element, if it exists
* @param list - a ptr to the linked list structure
* @param element - value to find
* @pre - unmodified linked list
* @post - unmodified linked list; position returned if found
*/
int findElementLinkedList(LinkedList* list, double element);
/** insertSortLinkedList()
* @brief - Perform an insertion sort on a LinkedList
* @param list - the LinkedList to sort
* @pre - unmodified linked list
* @post - sorted linked list
*/
void selSortLinkedList(LinkedList* list);
/** selSortLinkedList()
* @brief - Perform an selection sort on a LinkedList
* @param list - the LinkedList to sort
* @pre - unmodified linked list
* @post - sorted linked list
*/
void insertSortLinkedList(LinkedList* list);
#endif // LISTASLINKEDLIST_H