-
Notifications
You must be signed in to change notification settings - Fork 0
Контрольная работа(2) #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,3 +53,5 @@ dkms.conf | |
|
|
||
| # debug information files | ||
| *.dwo | ||
|
|
||
| *build/ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| #include <stdbool.h> | ||
| #include <stdio.h> | ||
| #include "task2.h" | ||
|
|
||
| bool TestEqual() | ||
| { | ||
| bool A[] = {0,1,1,0}; | ||
| bool B[] = {0,1,1,0}; | ||
| return CompareBin(A, B, 4) == 0; | ||
| } | ||
|
|
||
| bool TestCompareBin() | ||
| { | ||
| bool A[] = {0,1,0,1}; | ||
| bool B[] = {0,1,1,0}; | ||
| return CompareBin(A, B, 4) == -1; | ||
| } | ||
|
|
||
| bool TestOneBitbit() | ||
| { | ||
| bool A[] = {1}; | ||
| bool B[] = {0}; | ||
| return CompareBin(A, B, 1) == 1; | ||
| } | ||
|
|
||
| bool TestAllZero() | ||
| { | ||
| bool A[] = {0,0,0,0}; | ||
| bool B[] = {0,0,0,0}; | ||
| return CompareBin(A, B, 4) == 0; | ||
| } | ||
|
|
||
|
|
||
| int main() | ||
| { | ||
| printf("TestEqual: %s\n", TestEqual() ? "PASS" : "FAIL"); | ||
| printf("TestCompareBin: %s\n", TestCompareBin() ? "PASS" : "FAIL"); | ||
| printf("TestOneBitbit: %s\n", TestOneBitbit() ? "PASS" : "FAIL"); | ||
| printf("TestAllZero: %s\n", TestAllZero() ? "PASS" : "FAIL"); | ||
|
|
||
| return 0; | ||
| } |
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 4 балла за попытку. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| #include <stdio.h> | ||
| #include <stdlib.h> | ||
|
|
||
| typedef struct Node { | ||
| int value; | ||
| struct Node* next; | ||
| } Node; | ||
|
|
||
|
|
||
| Node* CreateNode(int value, Node* next) { | ||
| Node* n = (Node*)malloc(sizeof(Node)); | ||
| n->value = value; | ||
| n->next = next; | ||
| return n; | ||
| } | ||
|
|
||
| Node* reverse(Node* head) { | ||
| Node* prev = NULL; | ||
| Node* curr = head; | ||
| while (curr) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Если я правильно всё посчитал, то после одного шага цикла над списком из трех элементов, ссылка на последний элемент потеряется и всё. |
||
| Node* next = curr->next; | ||
| curr->next = prev; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Здесь можно записать в нулевой указатель |
||
| prev = curr; | ||
| curr = next; | ||
| } | ||
| return prev; | ||
| } | ||
|
|
||
| void FreeList(Node* head) { | ||
| while (head) { | ||
| Node* tmp = head; | ||
| head = head->next; | ||
| free(tmp); | ||
| } | ||
| } | ||
|
|
||
| typedef struct Queue { | ||
| Node* f; | ||
| Node* r; | ||
| } Queue; | ||
|
|
||
| Queue* createQueue() { | ||
| Queue* q = (Queue*)malloc(sizeof(Queue)); | ||
| q->f = NULL; | ||
| q->r = NULL; | ||
| return q; | ||
| } | ||
|
|
||
| void enqueue(Queue* q, int value) { | ||
| q->f = CreateNode(value, q->f); | ||
|
|
||
| } | ||
|
|
||
|
|
||
| void dequeue(){ | ||
|
|
||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| #include <stdio.h> | ||
| #include <stdbool.h> | ||
| #include "task2.h" | ||
|
|
||
|
|
||
| int CompareBin(bool A[], bool B[], int n) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Функции по стайлгайду называются в Также к функциям принято писать комментарии. Здесь он очень нужен, потому что трактовка возвращаемого значения нетривиальна. |
||
| { | ||
| for (int i = 0; i < n; i++) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. А если у чисел разная длина? Какой тогда контракт? |
||
| if (A[i] > B[i]) | ||
| return 1; | ||
| if (A[i] < B[i]) | ||
| return -1; | ||
| } | ||
| return 0; | ||
| } | ||
|
|
||
| int main() | ||
| { | ||
| int n; | ||
| scanf("%d", &n); | ||
|
|
||
| bool A[n], B[n]; | ||
|
|
||
| for (int i = 0; i < n; i++) | ||
| scanf("%d", (int*)&A[i]); | ||
|
|
||
| for (int i = 0; i < n; i++) | ||
| scanf("%d", (int*)&B[i]); | ||
|
|
||
| int r = CompareBin(A, B, n); | ||
|
|
||
| if (r > 0) | ||
| printf("A > B\n"); | ||
| else if | ||
| (r < 0) printf("A < B\n"); | ||
| else | ||
| printf("A = B\n"); | ||
|
|
||
| return 0; | ||
| } | ||
|
Comment on lines
+17
to
+40
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Зачем Вам в библиотеке интерактивный Ещё и с глупыми ошибками типа кривого форматирования и неициализированных переменных. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| #pragma once | ||
| #include <stdbool.h> | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Если здесь уже есть |
||
|
|
||
| int CompareBin(bool A[], bool B[], int n); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
6 баллов.