Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- // A simple CPP program to introduce
- // A linked list
- class Node {
- public:
- int data;
- Node *next;
- };
- // Program to create a simple linked
- // List with 3 nodes
- int main() {
- Node* head = NULL;
- Node* second = NULL;
- Node* third = NULL;
- // allocate 3 nodes in the heap
- head = new Node();
- second = new Node();
- third = new Node();
- head->data = 1; // Assign data in first node
- head->next = second; // Link first node with
- second->data = 2;
- second->next = third;
- third->data = 3;
- third->next = NULL;
- cout << endl;
- cout << second->next;
- Node* temp = head;
- while (temp != NULL) {
- cout << temp->data << " " << endl;
- temp = temp->next;
- }
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement