-
Notifications
You must be signed in to change notification settings - Fork 7
- #2
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
Open
drozdvadym
wants to merge
14
commits into
vitalWord:master
Choose a base branch
from
drozdvadym:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
- #2
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
7813b2b
First
0e87fca
Third
540fbff
Second
f711f88
Fix second
f249d7e
Third fixed
7301ddf
fix _MSC_VER
drozdvadym 665ad98
fix due to task
drozdvadym 393645f
Add destructor
08f0f91
Cosmetic
7c59027
Cosmetic
23edf8d
add free
81b7678
added original comment
drozdvadym 8fe41ac
Added second implementation of first task
7562456
Cosmetic
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,65 @@ | ||
| // ���������� ������. ��������� reverse_string ������ ��������� �� ����������� ������. | ||
| // Разверните строку. Указатель reverse_string должен | ||
| // указывать на развернутую строку. | ||
|
|
||
| #define USE_VERSION 1 | ||
|
|
||
| static const char* str = "The string!"; | ||
|
|
||
| #if (USE_VERSION == 1) | ||
|
|
||
| # include <stdio.h> | ||
| # include <string.h> | ||
| # include <stdlib.h> | ||
|
|
||
| void strreverse(char * aStr); | ||
|
|
||
| # define swap_char(left, right) { char _t = left; left = right; right = _t; } | ||
|
|
||
| # ifdef _MSC_VER | ||
| # define strdup _strdup | ||
| # endif | ||
|
|
||
| char* string = �The string!�; | ||
| int main() | ||
| { | ||
| char* reverse_string; | ||
| char* reverse_string = strdup(str); //strlen + alloc + memcpy | ||
|
|
||
| strreverse(reverse_string); | ||
|
|
||
| printf("%s\n", str); | ||
| printf("%s\n", reverse_string); | ||
|
|
||
| free(reverse_string); | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| void strreverse(char * p) | ||
| { | ||
| char *q = p + strlen(p); | ||
| for(--q; p < q; ++p, --q) | ||
| swap_char(*p, *q); | ||
| } | ||
|
|
||
| #endif | ||
|
|
||
| #if (USE_VERSION == 2) | ||
|
|
||
| # include <iostream> | ||
| # include <algorithm> | ||
| // std::reverse | ||
| # include <string> | ||
|
|
||
| int main () { | ||
| std::string result(str); | ||
|
|
||
| std::reverse(result.begin(), result.end()); | ||
|
|
||
| char* reverse_string = &result[0]; | ||
|
|
||
| std::cout << "Original: " << str << std::endl; | ||
| std::cout << "Reversed: " << reverse_string << std::endl; | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
| #endif | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,62 @@ | ||
| // �������� ������� Add(), ������� ������� ����� ������ List, �������������� ��� ������� ��������� value � ��������� ��� � ����� ������ l, ����������� �� ����. � ������� main() �������� ��������������������� ������, �� ���������� value �������: 1, 2, 3, 4 � 5. | ||
| // Напишите функцию Add(), которая создает новый объект List, инициализирует | ||
| // его входным значением value и добавляет его в конец списка l, полученного на вход. | ||
| // В функции main() создайте проинициализированный список, со значениями value равными: 1, 2, 3, 4 и 5. | ||
|
|
||
| #include <iostream> | ||
|
|
||
| struct List | ||
| { | ||
| int value; | ||
| List* next; | ||
| int value; | ||
| List* next; | ||
|
|
||
| ~List(); | ||
|
|
||
| void printList() const; | ||
| }; | ||
|
|
||
| // Add should create new List object, initialize it by value and add it to the end of the list. | ||
| // It should return pointer to the added List object. | ||
| List* Add(List* l, int value) | ||
| { | ||
| List *newElem = new List; | ||
| newElem->value = value; | ||
| newElem->next = NULL; | ||
|
|
||
| if (l) { | ||
| while (l->next) | ||
| l = l->next; | ||
|
|
||
| l->next = newElem; | ||
| } | ||
|
|
||
| return newElem; | ||
| } | ||
|
|
||
| int main(int argc, char* argv[]) | ||
| { | ||
| return 0; | ||
| List *l, *tmpList; | ||
| size_t i; | ||
|
|
||
| l = Add(NULL, 1); | ||
| for (i = 2, tmpList = l; i < 6; i++) | ||
| tmpList = Add(tmpList, i); | ||
|
|
||
| l->printList(); | ||
|
|
||
| delete l; | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| List::~List() | ||
| { | ||
| delete next; | ||
| } | ||
|
|
||
| void List::printList() const | ||
| { | ||
| std::cout << "The list is:"; | ||
| for (const List *iter = this; iter; iter = iter->next) | ||
| std::cout << " " << iter->value; | ||
| std::cout << std::endl; | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
думаю це варто випраивити, як і в інших файлах також