Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class ListElement
- {
- private:
- int key;
- ListElement* next;
- public:
- ListElement(int key, ListElement* next)
- {
- this->key = key;
- this->next = next;
- }
- int getKey()
- {
- return key;
- }
- ListElement* getNext()
- {
- return next;
- }
- };
- int main()
- {
- ListElement* firstElement = new ListElement(0, NULL);
- ListElement* secondElement = new ListElement(5, firstElement);
- ListElement* thirdElement = new ListElement(7, secondElement);
- ListElement* fourthElement = new ListElement(3, thirdElement);
- cout << fourthElement->getKey() << "\n";
- cout << fourthElement->getNext()->getKey() << "\n";
- cout << fourthElement->getNext()->getNext()->getKey() << "\n";
- cout << fourthElement->getNext()->getNext()->getNext()->getKey() << "\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement