user
Write a C++ library that implements a linked list


assistant
#include<iostream>
using namespace std;

struct Node {
    int data;
    struct Node *next;
};

// Add a new node to the end of the list 
void append(struct Node** head_ref, int new_data) 
{ 
    Node* new_node = new Node; 
  
    Node *last = *head_ref;
  
    new_node->data = new_data; 
  
    new_node->next = NULL; 
  
    if (*head_ref == NULL) { 
        *head_ref = new_node; 
        return; 
    } 
  
    while (last->next != NULL) 
        last = last->next; 
  
    last->next = new_node; 
    return; 
} 

// Delete the node at a given position 
void deleteNode(struct Node **head_ref, int position) 
{ 
    if (*head_ref == NULL) 
        return; 
    struct Node *temp = *head_ref; 
    if (position == 0) 
    { 
        *head_ref = temp->next;   
        free(temp);               
        return; 
    } 

   for (int i=0; temp!=NULL && i<position-1; i++) 
         temp = temp->next; 
  
    if (temp == NULL || temp->next == NULL) 
         return; 
  
   struct Node *next = temp->next->next; 

   free(temp->next);  
   temp->next = next;  
}