Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. class list{
  6.  
  7. private:
  8.     struct node{
  9.         string name;
  10.         node* next;
  11.     };
  12.     node* head;
  13.     node* curr;
  14. public:
  15.     list();
  16.     void addName(string s);
  17.     void print();
  18. };
  19.  
  20.  
  21. list::list(){
  22.     head = NULL;
  23.     curr = NULL;
  24. }
  25. void list::addName(string s){
  26.     node *n = new node;
  27.     n->name=s;
  28.     n->next=NULL;
  29.  
  30.     if(head!=NULL){
  31.         curr=head;
  32.         while(curr!=NULL){
  33.             curr=curr->next;
  34.         }
  35.         curr->next=n;
  36.         cout<<n->name;
  37.     }
  38. }
  39. void list::print(){
  40.     curr=head;
  41.     while(curr!=NULL){
  42.         cout<<curr->name<<' ';
  43.         curr=curr->next;
  44.     }
  45. }
  46.  
  47.  
  48. int main()
  49. {
  50.     list nou;
  51.     nou.addName("eu");
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement