Created
March 10, 2016 00:56
-
-
Save hallfox/2ff55176c2ea786dd38c to your computer and use it in GitHub Desktop.
This file contains 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
class LinkedList; | |
class Node { | |
public: | |
// You can do it this way but eehhhh | |
friend LinkedList; | |
Node(int data): data{data}, next{nullptr} {} | |
// Otherwise just use this if you have it | |
Node *get_next() { return next; } | |
private: | |
int data; | |
Node *next; | |
}; | |
// IMHO the better way to do it is to have Node be a struct | |
// Or have Node as an internal class of LinkedList | |
class LinkedList { | |
public: | |
LinkedList(); | |
LinkedList(const LinkedList& ll); | |
class Iterator { | |
public: | |
Iterator(); | |
Iterator operator++() { | |
// nullptr checking | |
curr = curr->next; | |
} | |
// yadda yadda | |
Iterator operator*(); | |
Iterator *operator->(); | |
}; | |
Iterator begin(); | |
// NOTE: Make sure it represents the theoretically place after the last | |
// Doing stuff to end() is undefined behavior | |
// Undefined behavior means: literally anything can happen | |
Iterator end(); | |
private: | |
Node *head; | |
}; | |
LinkedList::LinkedList(const LinkedList& ll) { | |
// LinkedLists are automatically friends with LinkedLists | |
Node *n = ll.head; | |
// Iterate over and deep copy... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment