#include<iostream>
using namespace std;
struct node
{
int data;
node * next;
} ;
typedef node * list;
int main( )
{
int dat;
char ch;
list first, last;
first= NULL ;
last= NULL ;
cout << "Do you want to enter data?(y/n)" << endl;
cin >> ch;
while ( ch== 'y' || ch== 'Y' )
{
cout << "Enter data" << endl;
cin >> dat;
if ( last== NULL )
{
last= new node;
last- > data= dat;
last- > next= last;
first= last;
}
else
{
last- > next= new node;
last- > next- > data= dat;
last- > next- > next= first;
}
cout << "Enter more data?(y/n)" << endl;
cin >> ch;
}
cout << "Displaying the ciruclar linked list" << endl;
cout << "Note: first is at " << first << " and last is at " << last << endl;
while ( first! = last)
{
cout << "Data is " << last- > data<< "\t At Address " << last- > next<< endl;
last= last- > next;
}
return 0 ;
}
I2luY2x1ZGU8aW9zdHJlYW0+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgpzdHJ1Y3Qgbm9kZQp7CiAgICBpbnQgZGF0YTsKICAgIG5vZGUgKm5leHQ7Cn07CnR5cGVkZWYgbm9kZSAqbGlzdDsKCmludCBtYWluKCkKewogICAgICAgIGludCBkYXQ7CiAgICAgICAgY2hhciBjaDsKICAgICAgICBsaXN0IGZpcnN0LCBsYXN0OwogICAgICAgIGZpcnN0PU5VTEw7CiAgICAgICAgbGFzdD1OVUxMOwogICAgICAgIGNvdXQ8PCJEbyB5b3Ugd2FudCB0byBlbnRlciBkYXRhPyh5L24pIjw8ZW5kbDsKICAgICAgICBjaW4+PmNoOwogICAgICAgIHdoaWxlKGNoPT0neSd8fGNoPT0nWScpCiAgICAgICAgewogICAgICAgICAgICBjb3V0PDwiRW50ZXIgZGF0YSI8PGVuZGw7CiAgICAgICAgICAgIGNpbj4+ZGF0OwogICAgICAgICAgICBpZihsYXN0PT1OVUxMKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBsYXN0PW5ldyBub2RlOwogICAgICAgICAgICAgICAgbGFzdC0+ZGF0YT1kYXQ7CiAgICAgICAgICAgICAgICBsYXN0LT5uZXh0PWxhc3Q7CiAgICAgICAgICAgICAgICBmaXJzdD1sYXN0OwogICAgICAgICAgICB9CiAgICAgICAgICAgIGVsc2UKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgbGFzdC0+bmV4dD1uZXcgbm9kZTsKICAgICAgICAgICAgICAgIGxhc3QtPm5leHQtPmRhdGE9ZGF0OwogICAgICAgICAgICAgICAgbGFzdC0+bmV4dC0+bmV4dD1maXJzdDsKICAgICAgICAgICAgfQogICAgICAgICAgICBjb3V0PDwiRW50ZXIgbW9yZSBkYXRhPyh5L24pIjw8ZW5kbDsKICAgICAgICAgICAgY2luPj5jaDsKCiAgICAgICAgfQogICAgICAgIGNvdXQ8PCJEaXNwbGF5aW5nIHRoZSBjaXJ1Y2xhciBsaW5rZWQgbGlzdCI8PGVuZGw7CiAgICAgICAgY291dCA8PCAiTm90ZTogZmlyc3QgaXMgYXQgIiA8PCBmaXJzdCA8PCAiIGFuZCBsYXN0IGlzIGF0ICIgPDwgbGFzdCA8PCBlbmRsOwogICAgICAgIHdoaWxlKGZpcnN0IT1sYXN0KQogICAgICAgIHsKICAgICAgICAgICAgY291dDw8IkRhdGEgaXMgIjw8bGFzdC0+ZGF0YTw8Ilx0QXQgQWRkcmVzcyAiPDxsYXN0LT5uZXh0PDxlbmRsOwogICAgICAgICAgICBsYXN0PWxhc3QtPm5leHQ7CiAgICAgICAgfQogICAgICAgIHJldHVybiAwOwp9Cg==