Created
January 4, 2018 21:50
-
-
Save adist98/cb41e8042b4b6db19f1725a7ca044ab7 to your computer and use it in GitHub Desktop.
Go to codes.
This file contains 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
// Singly Linked List implementation in c++ | |
#include <iostream> | |
using namespace std; | |
struct node | |
{ | |
int data; | |
node *next; | |
}; | |
class linked_list | |
{ | |
private: | |
node *head,*tail; | |
public: | |
linked_list() | |
{ | |
head = NULL; | |
tail = NULL; | |
} | |
void add_node(int n) | |
{ | |
node *tmp = new node; | |
tmp->data = n; | |
tmp->next = NULL; | |
if(head == NULL) | |
{ | |
head = tmp; | |
tail = tmp; | |
} | |
else | |
{ | |
tail->next = tmp; | |
tail = tail->next; | |
} | |
} | |
}; | |
int main() | |
{ | |
linked_list a; | |
a.add_node(1); | |
a.add_node(2); | |
return 0; | |
} | |
/* Go to | |
URL ="https://www.codesdope.com/blog/article/c-linked-lists-in-c-singly-linked-list/" | |
for a great explaination of singly linked list in c++ | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment