#include <iostream> #include <memory> using namespace std; struct node { shared_ptr<node> next; int datum; }; int main() { shared_ptr<node> ring_buffer_head = make_shared<node>(); shared_ptr<node> ring_buffer_cur = ring_buffer_head; ring_buffer_head->datum = 0; for (int i = 0; i < 10; i++) { ring_buffer_cur->next = make_shared<node>(); ring_buffer_cur = ring_buffer_cur->next; ring_buffer_cur->datum = i + 1; } // Complete the circle ring_buffer_cur->next = ring_buffer_head; ring_buffer_cur = ring_buffer_head; do { cout << ring_buffer_cur->datum << endl; ring_buffer_cur = ring_buffer_cur->next; } while (ring_buffer_cur != ring_buffer_head); return 0; }