Skip to content

Comments

ring queue(second test)#34

Open
Andrw-404 wants to merge 1 commit intomainfrom
secondTest
Open

ring queue(second test)#34
Andrw-404 wants to merge 1 commit intomainfrom
secondTest

Conversation

@Andrw-404
Copy link
Owner

No description provided.

#define STARTSIZE 10

typedef struct Queue {
int* array;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Используйте четыре пробела для отступов

Comment on lines +13 to +14
int count;
int size;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не очень удачный выбор имён переменных, непонятно, чем они отличаются

Comment on lines +11 to +12
int first;
int back;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Оно обычно head и tail, либо front и back, но так тоже ок

Queue* createQueue() {
Queue* queue = malloc(sizeof(Queue));
if (queue == NULL) {
return;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return что? Функция обещала вернуть указатель. Тут наверняка компилятор выдаёт предупреждение, а надо, чтобы программа компилировалась без предупреждений

}
queue->array = malloc(10 * sizeof(int));
if (queue->array == NULL) {
return;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

И потеряем указатель на уже выделенную под queue память


int dequeue(Queue* queue) {
if (isEmpty(queue)) {
return NULL;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NULL — это указатель, а функция обещает вернуть int. Так что NULL скастается к нулю, функция вернёт 0, вызывающий подумает, что в очереди 0 лежал. Тоже надо было предусмотреть код ошибки.

Comment on lines +67 to +68
int element = 0;
element = queue->array[queue->first];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Эм, зачем это в две фазы делается? :)

Comment on lines +76 to +80
queue->array = NULL;
queue->size = 0;
queue->count = 0;
queue->first = 0;
queue->back = 0;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А зачем это всё, и надо же ещё вернуть память, выделенную malloc на 18-й строчке?


typedef struct Queue Queue;

//function to add to the tail

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Надо пробел после //

Queue* queue = createQueue();
enqueue(queue, 1);
int res = dequeue(queue);
} No newline at end of file

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тесты бы ещё.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants