Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- class list{
- private:
- struct node{
- string name;
- node* next;
- };
- node* head;
- node* curr;
- public:
- list();
- void addName(string s);
- void print();
- };
- list::list(){
- head = NULL;
- curr = NULL;
- }
- void list::addName(string s){
- node *n = new node;
- n->name=s;
- n->next=NULL;
- if(head!=NULL){
- curr=head;
- while(curr!=NULL){
- curr=curr->next;
- }
- curr->next=n;
- cout<<n->name;
- }
- }
- void list::print(){
- curr=head;
- while(curr!=NULL){
- cout<<curr->name<<' ';
- curr=curr->next;
- }
- }
- int main()
- {
- list nou;
- nou.addName("eu");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement