Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- List deep_copy(List& original)
- {
- Node* current_original{original.first};
- List copy{};
- copy.first = new Node{current_original->value};
- Node* to = copy.first;
- while (current_original->next != nullptr) {
- current_original = current_original->next;
- to->next = new Node{current_original->value};
- to = to->next;
- }
- return copy;
- }
- /**
- *1. sätt current till original.first
- *2. kopiera det current pekar på, och lägg i copy.first
- *3. skapa to som pekar på det som l2.first pekar på
- *4. Flytta current till nästa element
- *5. kopiera det som current pekar på, och sätt to->next till kopian och sätt to = to->next
- *6. gå till steg 4 om current->next != nullptr
- */
Advertisement
Add Comment
Please, Sign In to add comment