Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class ListElement
  6. {
  7. private:
  8. int key;
  9. ListElement* next;
  10. public:
  11. ListElement(int key, ListElement* next)
  12. {
  13. this->key = key;
  14. this->next = next;
  15. }
  16. int getKey()
  17. {
  18. return key;
  19. }
  20. ListElement* getNext()
  21. {
  22. return next;
  23. }
  24. };
  25.  
  26. int main()
  27. {
  28. ListElement* firstElement = new ListElement(0, NULL);
  29. ListElement* secondElement = new ListElement(5, firstElement);
  30. ListElement* thirdElement = new ListElement(7, secondElement);
  31. ListElement* fourthElement = new ListElement(3, thirdElement);
  32.  
  33. cout << fourthElement->getKey() << "\n";
  34. cout << fourthElement->getNext()->getKey() << "\n";
  35. cout << fourthElement->getNext()->getNext()->getKey() << "\n";
  36. cout << fourthElement->getNext()->getNext()->getNext()->getKey() << "\n";
  37. return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement