Skip to content

Instantly share code, notes, and snippets.

@amitk
Created May 13, 2020 03:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amitk/1c6fa88e7e147ecbad62dd27ddaafb9d to your computer and use it in GitHub Desktop.
Save amitk/1c6fa88e7e147ecbad62dd27ddaafb9d to your computer and use it in GitHub Desktop.
A simple linked list in c++
#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