Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions 3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
// на вход. В функции main() создайте проинициализированный
// список, со значениями value равными: 1, 2, 3, 4 и 5.

#define NULL 0

struct List
{
int value;
Expand All @@ -14,10 +16,36 @@ struct List
// It should return pointer to the added List object.
List* Add(List* l, int value)
{
List* new_item = new List;
new_item->value = value;
new_item->next = NULL;

if (l) {
while (l->next)
l = l->next;
l->next = new_item;
}

return new_item;
}

void Free(List* l) {
if (l->next)
Free(l->next);
delete l;
}

int main(int argc, char* argv[])
{
return 0;
}
List* begin = Add(NULL, 1);
Add(begin, 2);
Add(begin, 3);
Add(begin, 4);
Add(begin, 5);
Copy link

Choose a reason for hiding this comment

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

вважаєш, що коротше не треба?

Copy link
Author

Choose a reason for hiding this comment

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

думаю, что для реализации алгоритма, это не принципиально)


// [...]

Free(begin);

return 0;
}