Guest User

Untitled

a guest
May 22nd, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. int main()
  2. {
  3. LinkedList ll;
  4. string test;
  5. test="we";
  6. ll.add("we");
  7. ll.add("are");
  8. cout << "ok working" << endl;
  9. return 0;
  10. }
  11.  
  12. class LinkedList
  13. {
  14. public:
  15. LinkedList();
  16. void add(string data);
  17. protected:
  18. private:
  19. class node{
  20. private:
  21. string data;
  22. public:
  23. node *next;
  24. node(string data,node *next);
  25. node(string data);
  26. node();
  27. };
  28.  
  29. node *head;
  30. };
  31.  
  32. LinkedList::LinkedList()
  33. {
  34. head=NULL;
  35. cout<<"ok";
  36. }
  37.  
  38.  
  39. void LinkedList::add(string data){
  40. if(!head){
  41. node tmphead(data,NULL);
  42. this->head=&tmphead;
  43. }else{
  44. node *temp;
  45. temp=head;
  46. while(temp->next){
  47. temp=temp->next;
  48. }
  49. node newnode(data);
  50. temp->next=&newnode;
  51. }
  52. }
  53. LinkedList::node::node(string data,node *next){
  54. LinkedList::node::data=data;
  55. LinkedList::node::next=next;
  56. cout<<"New node created with : "+data<< endl;
  57.  
  58. }
  59. LinkedList::node::node(){
  60. LinkedList::node::data="";
  61. LinkedList::node::next=NULL;
  62. //LinkedList::node::
  63. //this->data="";
  64. //this->next=NULL;
  65. }
  66. LinkedList::node::node(string data){
  67. LinkedList::node::data=data;
  68. LinkedList::node::next=NULL;
  69. }
Add Comment
Please, Sign In to add comment