Answers for "store data from limked list in c"

C++
18

how to make a linked list in c

typedef struct node{
    int value; //this is the value the node stores
    struct node *next; //this is the node the current node points to. this is how the nodes link
}node;

node *createNode(int val){
    node *newNode = malloc(sizeof(node));
    newNode->value = val;
    newNode->next = NULL;
    return newNode;
}
Posted by: Guest on June-21-2020
-3

linked list class c++ basic implementation

template<typename T>
class list {
  public:

    struct node {
        T value;
        node* next;
    };

    list() : hd(nullptr), tl(nullptr) {}

    node* head() { return hd; }
    node* tail() { return tl; }

    void insert(node* prior, T value);

    node* at(int i);    

    void erase(node* prior);
    void clear();

    void push_back(T value);
    void pop_back();

    void push_front(T value);
    void pop_front();

    int size();    

  private:
    node* hd, tl;
}
Posted by: Guest on November-09-2020

Browse Popular Code Answers by Language