+ 1
Are there linked lists in C++ like C?
2 ответов
+ 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; }
+ 1
Thank you @STEASY