Advertisement
Guest User

Untitled

a guest
Feb 17th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. //My classes:
  2.  
  3. class Node
  4. {
  5. int data;
  6. Node* next;
  7. public:
  8. Node();
  9. void setData(int d);
  10. void setNext(Node* n);
  11. int getData();
  12. Node* getNext();
  13. };
  14.  
  15.  
  16. class LinkList
  17. {
  18. Node* headPtr;
  19. int listSize;
  20. int check_Input(string n);
  21. Node* createNode();
  22. public:
  23. LinkList();
  24. Node* getHeadPtr();
  25. int getListSize();
  26. void addNode_start(int x);
  27. void addNode_end(int x);
  28. void addNode_middle(int x);
  29. int search(int key, int pos,Node* temp);
  30. void Reverse();
  31. void sortByVal();
  32. void sortByLink();
  33. void sortedInsert(int x);
  34. LinkList& operator=( LinkList &L);
  35. void print();
  36.  
  37. };
  38.  
  39. //The functions being called inside my overloaded function:
  40.  
  41. void Node::setData(int d)
  42. {
  43. data = d;
  44. }
  45.  
  46.  
  47. void Node::setNext(Node* n)
  48. {
  49. next = n;
  50. }
  51.  
  52.  
  53. int Node::getData()
  54. {
  55. return data;
  56. }
  57.  
  58.  
  59. Node* Node::getNext()
  60. {
  61. return next;
  62. }
  63.  
  64.  
  65. Node* LinkList:: createNode()
  66. {
  67. Node *newPtr;
  68. newPtr = (Node *)malloc(sizeof(Node));
  69. listSize++;
  70. return newPtr;
  71. }
  72.  
  73. LinkList& LinkList::operator=(LinkList &L)
  74. {
  75. if (this != &L)
  76. {
  77. Node* tail = NULL;
  78. Node* headPtr = NULL;
  79. Node* curr = L.getHeadPtr();
  80. while (curr != NULL)
  81. {
  82. if (headPtr == NULL)
  83. {
  84. headPtr = createNode();
  85. headPtr->setData(curr->getData());
  86. headPtr->setNext(NULL);
  87. tail = headPtr;
  88. }
  89. else
  90. {
  91. tail->setNext(createNode());
  92. tail = tail->getNext();
  93. tail->setData(curr->getData());
  94. tail->setNext(NULL);
  95. }
  96. curr = curr->getNext();
  97. }
  98. }
  99. return *this;
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement