Guest User

Untitled

a guest
Jul 18th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. Node* Node::createNode(int n)
  2. {
  3. Node newNode(n);
  4. Node *temp = &newNode;
  5. return temp;
  6. }
  7.  
  8. void Node::printNode(Node* node)
  9. {
  10. cout << node->data << "t" << node->next << endl;
  11. system("pause");
  12. }
  13.  
  14. int main(int argc, char* argv[])
  15. {
  16.  
  17. Node *head = Node::createNode(10);
  18. Node::printNode(head);
  19. return 0;
  20. }
  21.  
  22. Node Node::createNode(int n)
  23. {
  24. Node newNode(n);
  25. return newNode;
  26. }
  27.  
  28. std::unique_ptr<Node> Node::createNode(int n)
  29. {
  30. return std::unique_ptr<Node>(new Node(n));
  31. }
  32.  
  33. Node* Node::createNode(int n)
  34. {
  35. Node newNode(n); // create a node on stack
  36. Node *temp = &newNode; // get address of the node on stack
  37. return temp; // return that address
  38. } // and here the node is destructed!
  39.  
  40. Node newNode(n);
  41. Node *temp = &newNode;
  42. return temp;
  43.  
  44. Node* Node::createNode(int n)
  45. {
  46. Node newNode(n);
  47. Node *temp = &newNode;
  48. return temp;
  49. }
  50.  
  51. Node* Node::createNode(int n)
  52. {
  53. return new Node(n);
  54. }
Add Comment
Please, Sign In to add comment