fix length difference
now making a queue with size n will actually let you store n elements in it instead of n-1
This commit is contained in:
parent
df960e552c
commit
761c019407
2 changed files with 2 additions and 2 deletions
|
@ -7,7 +7,7 @@
|
||||||
int main(void) {
|
int main(void) {
|
||||||
srand((unsigned int)time(NULL));
|
srand((unsigned int)time(NULL));
|
||||||
|
|
||||||
Queue *q = queue_new(51, sizeof(long));
|
Queue *q = queue_new(50, sizeof(long));
|
||||||
|
|
||||||
for (size_t i = 0; i < 50; ++i) {
|
for (size_t i = 0; i < 50; ++i) {
|
||||||
long val = rand() % 1000;
|
long val = rand() % 1000;
|
||||||
|
|
|
@ -17,7 +17,7 @@ Queue *queue_new(size_t length, size_t element_size) {
|
||||||
ret->front = 0;
|
ret->front = 0;
|
||||||
ret->length = length;
|
ret->length = length;
|
||||||
ret->element_size = element_size;
|
ret->element_size = element_size;
|
||||||
ret->data = malloc(length * sizeof(void*));
|
ret->data = malloc((length + 1) * sizeof(void*));
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue