Algorithms_in_C  1.0.0
Set of algorithms implemented in C.
carray.h
1 /*
2  * CArray.h
3  *
4  * Author: Leonardo Vencovsky
5  * Created on 18/03/2018
6  *
7  * Modified by: Leonardo Vencovsky
8  * Last modified: 19/03/2018
9  *
10  * Header for Array in C
11  *
12  * Compiled in Visual Studio 2017
13  *
14  */
15 
16 #pragma once
17 
18 #ifdef __cplusplus
19 extern "C"
20 {
21 #endif
22 
23 #define ARRAY_ERASED -1
24 #define SUCCESS 0
25 #define INVALID_POSITION 1
26 #define POSITION_INIT 2
27 #define POSITION_NOT_INIT 3
28 #define POSITION_EMPTY 4
29 #define ARRAY_FULL 5
30 
31  typedef struct CArray
32  {
33  int *array;
34  int size;
35  } CArray;
36 
37  // +-------------------------------------+
38  // | Returns array |
39  // +-------------------------------------+
40  CArray *getCArray(int size);
41  CArray *getCopyCArray(CArray *array);
42 
43  // +-------------------------------------+
44  // | Input / Output |
45  // +-------------------------------------+
46  int insertValueCArray(CArray *array, int position, int value);
47  int removeValueCArray(CArray *array, int position);
48  int pushValueCArray(CArray *array, int value);
49  int updateValueCArray(CArray *array, int position, int value);
50 
51  // +-------------------------------------+
52  // | Erase |
53  // +-------------------------------------+
54  int eraseCArray(CArray *array);
55 
56  // +-------------------------------------+
57  // | Switching |
58  // +-------------------------------------+
59  int switchValuesCArray(CArray *array, int position1, int position2);
60  int reverseCArray(CArray *array);
61 
62  // +-------------------------------------+
63  // | Sorting |
64  // +-------------------------------------+
65  int bubbleSortCArray(CArray *array);
66  int selectionSortCArray(CArray *array);
67  int insertionSortCArray(CArray *array);
68  int blenderCArray(CArray *array);
69 
70  // +-------------------------------------+
71  // | Searching |
72  // +-------------------------------------+
73  int valueOcurranceCArray(CArray *array, int value);
74  CArray *valuePositionsCArray(CArray *array, int value);
75  int findMaxCArray(CArray *array);
76  int findMinCArray(CArray *array);
77 
78  // +-------------------------------------+
79  // | Display |
80  // +-------------------------------------+
81  int displayCArray(CArray *array);
82 
83 #ifdef __cplusplus
84 }
85 #endif
MAX_SIZE
#define MAX_SIZE
maximum number of elements in the set
Definition: union_find.c:8
MAX
#define MAX
max.
Definition: server.c:33
test
void test()
Test function.
Definition: decimal_to_binary_recursion.c:20
main
int main()
Driver code.
Definition: server.c:81
MAXLINE
#define MAXLINE
maximum characters per line
Definition: udp_client.c:27
int_to_string
char * int_to_string(uint16_t value, char *dest, int base)
Converts an integer value to a null-terminated string using the specified base and stores the result ...
Definition: int_to_string.c:25
MAXLINE
#define MAXLINE
maximum characters per line
Definition: udp_server.c:27
main
int main()
Driver Code.
Definition: int_to_string.c:77
PORT
#define PORT
port number to connect to
Definition: udp_server.c:26
main
int main()
Driver code.
Definition: udp_client.c:35
PORT
#define PORT
port number to connect to
Definition: client.c:29
test
static void test()
Test function.
Definition: int_to_string.c:51
main
int main()
Driver code.
Definition: client.c:70
swap
void swap(int *first, int *second)
Swap two values by using pointer.
Definition: bubble_sort.c:31
func
void func(int sockfd)
Continuous loop to send and receive over the socket.
Definition: server.c:47
main
int main()
Driver code.
Definition: udp_server.c:35
PORT
#define PORT
port number to connect to
Definition: udp_client.c:26
main
int main()
Driver Code.
Definition: decimal_to_binary_recursion.c:34
MAX
#define MAX
max.
Definition: client.c:28
min
#define min(a, b)
shorthand for minimum value
Definition: kohonen_som_topology.c:43
max
#define max(a, b)
shorthand for maximum value
Definition: kohonen_som_topology.c:39
main
int main(int argc, char **argv)
the main function take one argument of type char* example : .
Definition: c_atoi_str_to_integer.c:72
c_atoi
int c_atoi(const char *str)
the function take a string and return an integer
Definition: c_atoi_str_to_integer.c:16
PORT
#define PORT
port number to connect to
Definition: server.c:34
CArray
Definition: carray.h:32
func
void func(int sockfd)
Continuous loop to send and receive over the socket.
Definition: client.c:37
decimal_to_binary
int decimal_to_binary(unsigned int number)
Decimal to binary using recursion algorithm.
Definition: decimal_to_binary_recursion.c:14
test_c_atoi
void test_c_atoi()
test the function implementation
Definition: c_atoi_str_to_integer.c:56
SA
#define SA
shortname for sockaddr
Definition: client.c:30
SA
#define SA
shortname for sockaddr
Definition: server.c:35