Skip to content

Commit 9329e9b

Browse files
authored
Create README.md
1 parent b08cdd5 commit 9329e9b

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

README.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
### Dynamic-Queue in C
2+
3+
This is a dynamic queue implementation in C. It is able to store any kind of data. Note that if you pass pointer as type for the queue, you will need to handle the dealocation of the element each time you dequeue one.
4+
Furthermore the queue is dynamic so it can grow...
5+
6+
## Folder-organisation
7+
8+
In the inc folder you will find the header for each files In the src folder you will find the implementation of all the function.
9+
Here the `main` file is just mean as an utilization example.
10+
11+
## How to use it
12+
13+
First you will need to build the project, the makefile is provided with the program, so you just need to enter the following command at the racine of the workspace folder: mingw32-make. Ok so now, you have build the project, (the makefile is setup to compile the program for debug mode) you can now run the program by running the following once again at the racine of the workspace folder : .\bin\main.
14+
15+
In the program, you will be able to use multiple commands. They will be presented to you by a menu when the program is running.
16+
17+
### Create an empty queue
18+
```c
19+
int main() {
20+
queue* q = create_queue();
21+
queue_free(q); ///Need to be call to dealocate the memory !!!
22+
return 0;
23+
}
24+
25+
```
26+
27+
### Create a queue from an array
28+
```c
29+
int main() {
30+
queue* q = queue_create_from_list((int[]){0,1,2,3,4,5,6,7,8,9}, 10, sizeof(int));
31+
queue_free(q); ///Need to be call to dealocate the memory !!!
32+
return 0;
33+
}
34+
```
35+
36+
## Warning
37+
38+
Please do not create the bin and obj folder. They will be created by the makefile. Plus do not touch to the created files inside those two folders.
39+
40+
### Free the memory
41+
You need to call the function `queue_free(queue* q)` to dealocate memory at the end of the utilisation.
42+
```c
43+
int main() {
44+
queue* q = queue_create();
45+
queue_free(q); ///Need to be call to dealocate the memory !!!
46+
return 0;
47+
}
48+
```
49+
#### Free memory + queue data is dynamic
50+
If the data pass inside the queue is allocated dynamically you should avoid to call the function `queue_free(queue* q)`. Instead try something like:
51+
```c
52+
int main() {
53+
int *dynamic_int = malloc(sizeof(*dynamic_int));
54+
queue* q = queue_create();
55+
queue_push(dynamic_int);
56+
int len = queue_size(q);
57+
///Part to dealocate the memory you allocate
58+
for(int i=0; i<len; i++){
59+
free(queue_pop(q));
60+
}
61+
queue_free(q); ///Call it to fully dealocate the q pointer.
62+
return 0;
63+
}
64+
```

0 commit comments

Comments
 (0)