Skip to content

Commit b9a256d

Browse files
authored
[feature] API modules and show ranking option (#16)
2 parents c189f6b + d130be5 commit b9a256d

File tree

345 files changed

+121848
-124
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

345 files changed

+121848
-124
lines changed

.vscode/c_cpp_properties.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
{
44
"name": "Win32",
55
"includePath": [
6-
"${workspaceFolder}/**"
6+
"${workspaceFolder}/**",
7+
"${workspaceFolder}/src/cURL/include"
8+
79
],
810
"defines": [
911
"_DEBUG",

docs/api-collection

Lines changed: 0 additions & 113 deletions
This file was deleted.

libs/list/main.c

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ size_t getLength(List* _list) {
8181

8282
return length;
8383
}
84+
8485
// Methods
8586
unsigned char pushElement(List* _list, void* data, const size_t sizeOfData) {
8687
Node* newNode;
@@ -120,6 +121,34 @@ unsigned char popElement(List* _list, void* store, const size_t sizeOfStore) {
120121
return 1;
121122
}
122123

124+
void selectionSort(List* _list, int (*cmp)(const void* a, const void* b)) {
125+
void* aux;
126+
unsigned tam;
127+
List *minor, *iterator;
128+
129+
if (!(*_list)) return;
130+
131+
while ((*_list)->__next) {
132+
iterator = &(*_list)->__next;
133+
minor = _list;
134+
while (*iterator) {
135+
if (cmp((*minor)->__data, (*iterator)->__data) > 0) minor = iterator;
136+
iterator = &(*iterator)->__next;
137+
}
138+
if (*minor != *_list) {
139+
aux = (*_list)->__data;
140+
tam = (*_list)->__sizeOfData;
141+
142+
(*_list)->__data = (*minor)->__data;
143+
(*_list)->__sizeOfData = (*minor)->__sizeOfData;
144+
145+
(*minor)->__data = aux;
146+
(*minor)->__sizeOfData = tam;
147+
}
148+
_list = &(*_list)->__next;
149+
}
150+
}
151+
123152
void randomSort(List* _list) {
124153
size_t length = 0;
125154
size_t index = 0;
@@ -138,6 +167,25 @@ void randomSort(List* _list) {
138167

139168
_list = head;
140169

170+
if (length == 1) {
171+
return;
172+
}
173+
if (length == 2) {
174+
rndIndex = (rand() % (length));
175+
176+
if (rndIndex == index) return;
177+
178+
helper = __getElementAt(head, rndIndex);
179+
auxPointer = (*_list)->__data;
180+
elementSize = (*_list)->__sizeOfData;
181+
182+
(*_list)->__data = helper->__data;
183+
(*_list)->__sizeOfData = helper->__sizeOfData;
184+
185+
helper->__data = auxPointer;
186+
helper->__sizeOfData = elementSize;
187+
return;
188+
}
141189
while ((*_list) != NULL) {
142190
while ((rndIndex = (rand() % (length))) == index);
143191
helper = __getElementAt(head, rndIndex);
@@ -154,3 +202,10 @@ void randomSort(List* _list) {
154202
index++;
155203
}
156204
}
205+
206+
void map(List* _list, action _action, void* punt) {
207+
while (*_list) {
208+
_action((*_list)->__data, punt);
209+
_list = &(*_list)->__next;
210+
};
211+
}

libs/list/main.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ unsigned char pushElement(List* _list, void* data, const size_t sizeOfData);
3333

3434
unsigned char popElement(List* _list, void* store, const size_t sizeOfStore);
3535

36+
void selectionSort(List* _list, int (*cmp)(const void* a, const void* b));
37+
3638
void randomSort(List* _list);
3739

40+
typedef void (*action)(void* data, void* data2);
41+
42+
void map(List* _list, action _action, void* punt);
43+
3844
#endif // LIBS__LIST_H_INCLUDED

0 commit comments

Comments
 (0)