C_Algorithms 2.0.0
Documentation
Loading...
Searching...
No Matches
main.c
Go to the documentation of this file.
1
2#include <stdio.h>
3#include <stdlib.h>
4
5#include "recursiveFib.h"
6#include "dynamicFib.h"
7#include "patternSearch.h"
8#include "stack.h"
9#include "queue.h"
10#include "doublyLinkedList.h"
11
12
13void FunctionCall();
14
15
19int main(void) // int argc, char const *argv[]
20{
21 FunctionCall();
22
23 return 0;
24}
25
26
32{
33 while(1)
34 {
35 char func[2];
36 printf("Which function du you want to test: ");
37 fgets(func, 3, stdin);
38
39 switch (func[0])
40 {
41 case 'a':
42 {
43 // Works fine for smaller numbers ->
44 // Really slow with higher numbers >= 40
45 int num = 10;
46 printf("\nRunning recursive fibonacci function with value of %d...\n", num);
47 printf("RecursiveFib(%d) = ", num);
48 RecursiveFib(num);
49 printf("\n");
50 //exit(0);
51 break;
52 }
53 case 'b':
54 {
55 //Really fast also works with higher numbers
56 int num = 60;
57 printf("\nRunning dynamic fibonacci function with value of %d...\n", num);
58 printf("RecursiveFib(%d) = ", num);
59 DynamicFib(num);
60 printf("\n");
61 break;
62 }
63 case 'c':
64 {
65 //Search for a specific pattern in a Text
66 char text[] = "THIS IS A TEXT TO SEARCH A PATTERN";
67 char pattern[] = "IS A";
68
69 printf("\nRunning pattern search...\n");
70
71 uint32_t x = PatternSearch(text, pattern);
72 if (x == -1)
73 {
74 printf("No matched pattern found!\n");
75 }
76 printf("Pattern found at position %d\n", x);
77
78 printf("\n");
79 break;
80 }
81 case 'd':
82 //Creating your own Stack to Push and pop your data
83 Stack();
84 exit(0);
85 break;
86 case 'e':
87 //Creating your own Queue to Push and pop your data
88 Queue();
89 exit(0);
90 break;
91 case 'f':
92 {
93 printf("\nRunning double linked list...\n");
94
95 List *list = createList();
96 Node *node = createNode();
97
98 node->data_ = 10;
99 appendNodeToEndOfList(list, node, false);
100
101 node = createNode();
102 node->data_ = 20;
103 appendNodeToEndOfList(list, node, false);
104
105 node = createNode();
106 node->data_ = 120;
107 appendNodeToEndOfList(list, node, false);
108
109 printList(list);
110
111 freeList(list);
112
113 printf("\n");
114
115 break;
116 }
117
118 case 'X':
119 case 'x':
120 //Exiting the programm
121 exit(0);
122
123 case '-':
124 switch (func[1])
125 {
126 case 'h':
127 printf("\nEnter the following characters to call the specific functions:\n");
128 printf("(a): Recursive Fibonacci\n");
129 printf("(b): Dynamic Fibonacci\n");
130 printf("(c): Patternsearch\n");
131 printf("(d): Stack\n");
132 printf("(e): Queue\n");
133 printf("(f): Double linked list\n");
134 printf("(X): Exit the programm\n\n");
135 break;
136
137 default:
138 printf("Invalid argument. Use -h for help.\n");
139 break;
140 }
141 break;
142 default:
143 printf("Invalid argument. Use -h for help.\n");
144 break;
145 }
146 fflush(stdin);
147 }
148}
149
150
151
152
Node * appendNodeToEndOfList(List *list, Node *node, bool check_for_existing_node)
Append a node to the end of a list.
Node * createNode(void)
Allocates memory for a new node and initalizes it.
void printList(List *list)
Print the whole List without trailing .
bool freeList(List *list)
Frees the memory of a list and all nodes in it.
List * createList(void)
Allocates memory for a new list and initalizes it.
void DynamicFib(int number)
Prints the return value of the called function RecFib.
Definition dynamicFib.c:31
void FunctionCall()
Easy access to all functions of the repository.
Definition main.c:31
int main(void)
This is the main function remove the // befor the function you want to test.
Definition main.c:19
uint32_t PatternSearch(char *text, char *pattern)
PatSearch is a Function to search for specific patterns in a text. (Be aware that its case sensitive!...
void Queue()
Definition queue.c:163
void RecursiveFib(int number)
Prints the return value of the called function RecFib.
void Stack()
Definition stack.c:148