Skip to content

Instantly share code, notes, and snippets.

@adist98
Created January 4, 2018 21:50
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 adist98/cb41e8042b4b6db19f1725a7ca044ab7 to your computer and use it in GitHub Desktop.
Save adist98/cb41e8042b4b6db19f1725a7ca044ab7 to your computer and use it in GitHub Desktop.
Go to codes.
// 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