LL1.cpp
void LL1::insertAt(int pos, int x){
        Node *p;
        Node *newNode;

        // Check that pos is a valid index
        if (pos <= size){
                newNode = new Node; //new node
                newNode->data = x;

                // Deal with case when item is to be inserted at the head of the list
                if (pos == 0){
                        newNode->next = head;
                        head = newNode;
                }// if(pos == 0)
                else{
                        p = head;
                        // Move to position BEFORE insertion point
                        for(int i = 0; i < pos-1; i++){
                                // Check that p points to a node
                                // Note using exception handling should throw an exception here
                                if(p == NULL){
                                        return;
                                }
                                p = p->next;
                        }//for
                        // Insert node
                        newNode->next = p->next;
                        p->next = newNode;
                }//else (pos != 0)
                size++;
        }//else (pos >= size) do nothing
}
// Inserts a new node at the given position (or index) in the list

Inserts a new node at the given position (or index) in the list
Inserts a new node at the given position ( or index ) in the list
void LL1::insertAt(int pos, int x){
        Node *p;
        Node *newNode;
        if (pos <= size){
                newNode = new Node; 
                newNode->data = x;
                if (pos == 0){
                        newNode->next = head;
                        head = newNode;
                }
                else{
                        p = head;
                        for(int i = 0; i < pos-1; i++){
                                if(p == NULL){
                                        return;
                                }
                                p = p->next;
                        }
                        newNode->next = p->next;
                        p->next = newNode;
                }
                size++;
        }
}
void LL1 :: insertAt ( int pos , int x ) { Node * p ; Node * newNode ; if ( pos <= size ) { newNode = new Node ; newNode -> data = x ; if ( pos == 0 ) { newNode -> next = head ; head = newNode ; } else { p = head ; for ( int i = 0 ; i < pos - 1 ; i ++ ) { if ( p == NULL ) { return ; } p = p -> next ; } newNode -> next = p -> next ; p -> next = newNode ; } size ++ ; } }
Inserts a new node at the given position (or index) in the list
Inserts a new node at the given position ( or index ) in the list
// Check that pos is a valid index
 //new node
 // Deal with case when item is to be inserted at the head of the list
 // if(pos == 0)
 // Move to position BEFORE insertion point
 // Check that p points to a node
 // Note using exception handling should throw an exception here
 //for
 // Insert node
 //else (pos != 0)
 //else (pos >= size) do nothing
