Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include<bits/stdc++.h>
- using namespace std;
- class Node{
- public:
- int data;
- Node *next;
- };
- void print(Node *n){
- while(n!=NULL){
- cout<<n->data <<" ";
- n= n->next;
- }
- }
- int main()
- {
- Node* head=NULL;
- Node* second=NULL;
- Node* third=NULL;
- //kreiranje na 3 objekti
- 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
- second->data = 2;// assign data to second node
- second -> next = third; //Link second node with third
- third -> data = 3 ;// assign data to third node
- third -> next = NULL;
- print(head);
- return 0;
- }
Add Comment
Please, Sign In to add comment