-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
66 lines (53 loc) · 1.51 KB
/
main.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include<stdio.h>
#include <stdlib.h>
#include "algorithms/bubble_sort.h"
#include "data-structures/dynamic_array.h"
#include "data-structures/linked_list.h"
void dynamic_array_test();
void linked_list_test();
int main(int argc, char* argv[]){
linked_list_test();
return 0;
}
void linked_list_test(){
LinkedList* source = linked_list_init(12, NULL);
linked_list_add(source, 43);
linked_list_add(source, 22);
linked_list_add(source, 16);
linked_list_remove(source);
linked_list_add(source, 32);
linked_list_add(source, 22);
linked_list_add(source, 895);
linked_list_remove(source);
linked_list_add(source, 85);
linked_list_remove(source);
linked_list_remove(source);
linked_list_remove(source);
linked_list_add(source, 79);
linked_list_remove(source);
linked_list_add(source, 190);
linked_list_add(source, 51);
printf("Values in list : ");
LinkedList* tail = source;
while(tail != NULL){
printf("%d ", tail->value);
tail = tail->next;
}
printf("\n");
}
void dynamic_array_test(){
printf("Enter a sequence of integers you wish to to sort (e.g., 1 5 8 93 24...), followed by a period (.):\n");
DynamicArray* dynamic = dynamic_init(1);
int val;
while (scanf("%d", &val) == 1) { // needs better input parsing
dynamic_insert(dynamic, val);
}
bubble_sort(dynamic->array, dynamic->length);
printf("Bubble-Sorted array is : ");
for(size_t i = 0; i < dynamic->length; ++i){
printf("%d ", dynamic->array[i]);
}
printf("\n");
free(dynamic->array);
free(dynamic);
}