refresh
This commit is contained in:
parent
ea7b709255
commit
29076c8d00
Binary file not shown.
@ -10,11 +10,11 @@ struct pizza {
|
||||
};
|
||||
|
||||
int read_pizza_list(struct pizza* list) {
|
||||
int counter = 0;
|
||||
char line[200];
|
||||
int counter = 0; // считает, сколько пицц реально прочитано
|
||||
char line[200]; // буфер для строк
|
||||
for (int i=0; i < LIST_SIZE; i++) {
|
||||
struct pizza item;
|
||||
memset(&item,0,sizeof(struct pizza));
|
||||
memset(&item,0,sizeof(struct pizza)); //заполняем память нулями
|
||||
if (fgets(line, sizeof(line), stdin)==NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
@ -10,11 +10,11 @@ struct station* create_station() {
|
||||
return s;
|
||||
}
|
||||
|
||||
int select_track(struct station* s, const char* target) {
|
||||
int select_track(struct station* s, const char* target) { //в какой bucket положить строку.
|
||||
unsigned long hash = 5381; //5381 это алгоритм DJB2
|
||||
int c;
|
||||
|
||||
while ((c = *target++)) { // не забываем ++ чтобы идти по строке
|
||||
while ((c = *target++)) {
|
||||
hash = ((hash << 5) + hash) + c; //hash << 5 сдвигает все биты числа hash на 5 позиций влево. Это тоже самое, что умножить на 2 в пятой степени
|
||||
}
|
||||
|
||||
@ -53,7 +53,7 @@ void add_target_capacity(struct station* s, const char* target, int capacity) {
|
||||
prev->next = new_car;
|
||||
}
|
||||
|
||||
int get_target_capacity(struct station* s, const char* target) {
|
||||
int get_target_capacity(struct station* s, const char* target) { //ищет станцию и возвращает её capacity.
|
||||
if (!s || !target) return 0;
|
||||
|
||||
int index = select_track(s, target);
|
||||
|
||||
@ -19,11 +19,11 @@ static TreeNode* read_tree_node() {
|
||||
if (buffer[0] == '\n' || buffer[0] == '\r')
|
||||
return NULL;
|
||||
|
||||
TreeNode *node = calloc(1, sizeof(TreeNode));
|
||||
TreeNode *node = calloc(1, sizeof(TreeNode)); //Создаём новый узел дерева.
|
||||
if (!node)
|
||||
exit(1);
|
||||
|
||||
strncpy(node->text, buffer, MAXLINE - 1);
|
||||
strncpy(node->text, buffer, MAXLINE - 1); //M чтобы оставить место для \0
|
||||
|
||||
if (node->text[0] == '*') {
|
||||
node->yes_branch = NULL;
|
||||
@ -43,7 +43,7 @@ static void free_tree(TreeNode *root) {
|
||||
free(root);
|
||||
}
|
||||
|
||||
static int count_leafs(TreeNode *root) {
|
||||
static int count_leafs(TreeNode *root) { //количество ответов
|
||||
if (!root) return 0;
|
||||
if (!root->yes_branch && !root->no_branch)
|
||||
return 1;
|
||||
|
||||
0
sk2/Makefile
Normal file
0
sk2/Makefile
Normal file
0
sk2/calculator.c
Normal file
0
sk2/calculator.c
Normal file
0
sk2/calculator.h
Normal file
0
sk2/calculator.h
Normal file
0
sk2/main.c
Normal file
0
sk2/main.c
Normal file
Loading…
Reference in New Issue
Block a user