+ 1

Are there linked lists in C++ like C?

1st Dec 2017, 4:53 PM
GOWTHAM PARA
2 Answers
+ 7
yes ,link list is present in c++ too like c it is used like this #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; }
1st Dec 2017, 5:36 PM
GAWEN STEASY
GAWEN STEASY - avatar
+ 1
Thank you @STEASY
2nd Dec 2017, 4:38 AM
GOWTHAM PARA