//-------------------------------------------------------------------------- // Header file #ifndef _CIRCULAR_LIST_H_ #define _CIRCULAR_LIST_H_ #include class Circular_List { private: class Element; public: Circular_List() : entry(nullptr) {} ~Circular_List(); Circular_List(Circular_List const&) = delete; Circular_List& operator=(Circular_List const&) = delete; void insert(std::string const& str); void print() const; class Iterator { public: Iterator(Element* e) : pos(e) {} ~Iterator() = default; Iterator(Iterator const&) = default; Iterator& operator=(Iterator const&) = default; bool operator!=(Iterator const& i) { return pos != i.pos; } operator bool() { return pos != nullptr; } Iterator& operator++() { pos = pos->next; return *this;} std::string operator*() { return pos->name; } private: Element* pos; }; Iterator begin() const { return Iterator(entry ? entry->next : nullptr); } Iterator end() const { return Iterator(nullptr); } private: class Element { public: Element(std::string const& s, Element* e = nullptr) : name(s), next(e) {} ~Element() { delete next; } Element(Element&) = delete; Element& operator=(Element const&) = delete; std::string name; Element* next; }; Element* entry; }; #endif //-------------------------------------------------------------------------- // Implementation file #include Circular_List::~Circular_List() { } void Circular_List::insert(std::string const& str) { } void Circular_List::print() const { } //-------------------------------------------------------------------------- // Main program #include using namespace std; int main() { Circular_List l; string name; cout << "Skriv in namn för spelare, avsluta med Ctrl-D." << endl; cout << "Namn? "; while ( cin >> name ) { l.insert(name); cout << "Listans innehåll:" << endl; l.print(); cout << endl << "Namn? "; } cout << endl; cout << "Tjugo stegningar i listan:" << endl; int j = 0; for (Circular_List::Iterator i = l.begin(); i != l.end() && j < 20; ++i, ++j) { cout << *i << "->"; } cout << endl; return 0; }