fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. class Node{
  4. public:
  5. string data;
  6. Node* next;
  7. Node(const string& data){
  8. this->data=data;
  9. this->next=nullptr;
  10. }
  11. };
  12. class CLL{
  13. public:
  14. Node* head;
  15. Node* tail;
  16. CLL(){
  17. this->head=nullptr;
  18. this->tail=nullptr;
  19. }
  20. void insert(const string& s){
  21.  
  22. Node* new_node=new Node(s);
  23. if(!head){
  24. head=new_node;
  25. tail=new_node;
  26. new_node->next=new_node;
  27. }else{
  28. tail->next=new_node;
  29. new_node->next=head;
  30. tail=new_node;
  31.  
  32. }
  33. }
  34.  
  35. bool display(){
  36. if(!head){return false;}
  37. cout<<"nayaya"<<endl;
  38. Node* temp;
  39. temp=head;
  40. do{
  41. cout<<temp->data;
  42. temp=temp->next; //this points to next pointer
  43. }while(temp->next!=head);
  44. return true;
  45. }
  46.  
  47. };
  48. int main() {
  49. CLL ok;
  50. string s;
  51. while(getline(cin,s)){
  52. transform(s.begin(),s.end(),s.begin(),::tolower);
  53. if(s=="exit") break;
  54. ok.insert(s);
  55. }
  56. ok.display();
  57. return 0;
  58. }
Success #stdin #stdout 0.01s 5320KB
stdin
asha
prem
wow
noono
exit
stdout
nayaya
ashapremwow