Created
May 13, 2020 03:17
-
-
Save amitk/1c6fa88e7e147ecbad62dd27ddaafb9d to your computer and use it in GitHub Desktop.
A simple linked list in c++
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<bits/stdc++.h> | |
using namespace std; | |
//Define structure of linked list. i.e each block in linked list | |
struct Node { | |
int data; | |
Node* link; | |
}; | |
/* head tail | |
| | | |
| | | |
+---+---+ +---+---+ | |
| 1 | o----->| 2 | NULL | |
+---+---+ +---+---+ | |
*/ | |
int main () { | |
Node* Head = new Node(); | |
Node* Tail = new Node(); | |
Head->data = 10; | |
Tail->data = 20; | |
Head->link = Tail; | |
Tail->link = NULL; | |
cout<<"Head data: "<<Head->data<<endl; | |
cout<<"Tail data "<<Head->link->data<<" = "<<Tail->data<<endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment