-
Notifications
You must be signed in to change notification settings - Fork 7
task done #6
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: master
Are you sure you want to change the base?
task done #6
Changes from all commits
679a25a
adb9b55
36cc4b7
7f61437
db4f417
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 |
|---|---|---|
| @@ -1,11 +1,19 @@ | ||
| // Разверните строку. Указатель reverse_string должен | ||
| // указывать на развернутую строку. | ||
|
|
||
| #include <cstring> | ||
| char* string = "The string!"; | ||
|
|
||
| int main() | ||
| { | ||
| char* reverse_string; | ||
|
|
||
| int Len = strlen(string); | ||
| reverse_string = new char[Len + 1]; | ||
| reverse_string[Len] = '\0'; // ending 0 | ||
| for(int beg = 0, end = Len - 1; beg <= end; beg++, end--) | ||
| { | ||
| reverse_string[beg] = string[end]; | ||
| reverse_string[end] = string[beg]; | ||
| } | ||
| delete [] reverse_string; | ||
| return 0; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,10 +14,34 @@ struct List | |
| // It should return pointer to the added List object. | ||
| List* Add(List* l, int value) | ||
| { | ||
|
|
||
| List * new_last = new List(); | ||
| new_last->next = nullptr; | ||
| new_last->value = value; | ||
| if(!l) // if empty | ||
| return new_last; | ||
| while(l->next) // find the last element | ||
| l = l->next; | ||
| l->next = new_last; | ||
| return new_last; | ||
|
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. новий_останній, як же тут пахне копіпастом=)
Author
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. Поясніть чи підтвердіть, будь ласка, вашу думку. 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. а, до мене нарешті дійла ваша думка. Я подумав, що мало бути new_list. це було б очевидно для мене (new_list = new List...) |
||
| } | ||
|
|
||
| void FreeList(List* head) | ||
| { | ||
| if(!head) | ||
| return; | ||
| FreeList(head->next); | ||
| delete head; | ||
| head = nullptr; | ||
| } | ||
| int main(int argc, char* argv[]) | ||
| { | ||
| const int N = 6; | ||
| List * l = Add(nullptr, 1); | ||
| for(int i = 2; i < N; i++) | ||
| { | ||
| Add(l, i); | ||
| } | ||
| FreeList(l); | ||
|
|
||
| return 0; | ||
| } | ||
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.
а если c_kM четное?
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.
если c_kM четное, тогда функция все равно будет работать, ибо посмотри на условие выполнения вложенного цикла ниже
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.
Согласен