C++ linked list with too many pointers Can someone tell me how I can improve this code? It works ok, but I feel that I'm using too many pointers.

#include &lt;iostream&gt;
using namespace std;
struct link{
    int data;
    link *next;
};
class link_list{
private:
    int boundaries = 0;
    link *tail;
    link *temp;
    link *head = NULL;
public:

    void add_node(int data){

        temp = new link;
        temp-&gt;data = data;
        temp-&gt;next = NULL;
        if (head == NULL){
            head = temp;
            boundaries++;
        }
        else{
            link *tail = head;
            while (tail-&gt;next != NULL){
                tail = tail-&gt;next;
            }
            tail-&gt;next = temp;
            boundaries++;
        }
    }
    void delete_b(){
        link *end = head;
        link *next_to_end = NULL;
        while (end-&gt;next != NULL){
            next_to_end = end;
            end = end-&gt;next;
        }
        next_to_end-&gt;next = NULL;
        end = NULL;
        boundaries--;
    }
    void add_front(int data){
        link *ptr = new link;
        ptr-&gt;next = head;
        ptr-&gt;data = data;
        head = ptr;
        boundaries++;

    }
    void delete_front(){
        link *new_head = head;
        new_head = head-&gt;next;
        head = NULL;
        head = new_head;
        boundaries--;

    }


    void add_by_position(int data, int pos){
        link *node = new link;
        link *linker = head;
        node-&gt;data = data;
        for (int i = 0; i &lt; pos; i++){
            linker = linker-&gt;next;
        }
        node-&gt;next = linker;
        linker = head;
        for (int i = 0; i &lt; pos - 1; i++){
            linker = linker-&gt;next;
        }
        linker-&gt;next = node;
        boundaries++;

    }

    void show(){
        link *sh = head;
        while (sh){ cout &lt;&lt; sh-&gt;data &lt;&lt; endl; sh = sh-&gt;next; }

    }



};


int main()
{
    link_list obj;
    obj.add_node(7);
    obj.add_node(5);

    obj.add_node(8);


    obj.show();
}
struct link{
    int data;
    link *next;
};


Are you sure you want this to be outside of the class? This could be in the private section in the class link_list since the outside world does not need to know of this class at all.



int boundaries = 0;


What is boundaries? It seems like this is your actual size of the list but I had to check your code to make sure what it is. Call it size or entries or something like this.



link *tail;
link *temp;
link *head = NULL;


There is no reason to have temp as a instance variable. And you do not use tail in your code, so drop them both. And use nullptr instead of NULL.



void add_node(int data){

    temp = new link;
    temp-&gt;data = data;
    temp-&gt;next = NULL;
    if (head == NULL){
        head = temp;
        boundaries++;
    }
    else{
        link *tail = head;
        while (tail-&gt;next != NULL){
            tail = tail-&gt;next;
        }
        tail-&gt;next = temp;
        boundaries++;
    }
}


Again, use nullptr. And if you had used your tail you wouldn't need to iterate over the whole list to get to the end.



void delete_b(){
    link *end = head;
    link *next_to_end = NULL;
    while (end-&gt;next != NULL){
        next_to_end = end;
        end = end-&gt;next;
    }
    next_to_end-&gt;next = NULL;
    end = NULL;
    boundaries--;
}


What's b? (Oh yeah, I think I don't need to remind you about nullptr again.)



void add_front(int data){
    link *ptr = new link;
    ptr-&gt;next = head;
    ptr-&gt;data = data;
    head = ptr;
    boundaries++;

}


add_node and add_front? What's the difference? Sure, I know what the difference is; I've seen the code. However, I don't like to look through the code to see what a function does. Call them add_front and add_back or something like this (head and tail might fit better, programmers will understand).



void delete_front(){
    link *new_head = head;
    new_head = head-&gt;next;
    head = NULL;
    head = new_head;
    boundaries--;

}


What is this playing around? That's three useless lines of code:

void delete_front(){
    link* tmp = head;
    head = head-&gt;next;
    delete tmp;
    boundaries--;
}




void add_by_position(int data, int pos){
    link *node = new link;
    link *linker = head;
    node-&gt;data = data;
    for (int i = 0; i &lt; pos; i++){
        linker = linker-&gt;next;
    }
    node-&gt;next = linker;
    linker = head;
    for (int i = 0; i &lt; pos - 1; i++){
        linker = linker-&gt;next;
    }
    linker-&gt;next = node;
    boundaries++;

}


by_position sounds silly. Call it add_at. And why do you reset linker and start over again? That's totally unnecessary. 

void add_at(int data, int pos){
    link *node = new link;
    node-&gt;data = data;
    boundaries++;
    if(pos == 0) {
      node-&gt;next = head;
      head = node;
      return;
    }

    link *linker = head;
    for (int i = 0; i &lt; pos - 1; i++){
        linker = linker-&gt;next;
    }
    node-&gt;next = linker-&gt;next;
    linker-&gt;next = node;
}




You should also delete the nodes in your delete/remove functions.

That's everything for now. You could've easily made a template out of this class, however, you should first fix your problems and then - if you like - ask another question with your new code.