remove_nodesFromTheList(current, next, changeObject, pointerChange) {
        var removedNodes = current.getLinkedListForStep().LinkedListNodes.
        filter(comparer(next.getLinkedListForStep().LinkedListNodes));
        if (changeObject.To === 0) //means that the list will be null
        {
            for (var i = 0; i < this.pointersForVisualization.size(); i++) //make all pointers to null
                this.nullifyPointer(i);
            for (i = current.getLinkedListForStep().size() - 1; i >= 0; i--) {
                this.JsavLinkedList.remove(i);
                //Update the current Linked List stpe nodes
                current.getLinkedListForStep().removeAt(i);
            }
            return;
        }
        //We need to determine if we should remove first or move the pointer first
        //if the pointer pointes to a node after a removed node so it is normal to see a change in the index of the node
        //if it points to a node before the removed one so we should apply the pointer change

        var after = false;
        if(pointerChange!== null){
        var oldPointerPointeeIndex = pointerChange.nodePosition;
        var differenceInIndices = pointerChange.nodePosition - pointerChange.To;
        for (var i = 0; i < removedNodes.length; i++) {
            var node = removedNodes[i];
            var nodeIndex = current.getLinkedListForStep().getNodeLocation(node.getReference());
            if (nodeIndex < oldPointerPointeeIndex)
                differenceInIndices--;
        }
    }
        if (pointerChange !== null && differenceInIndices !== 0) {
            var pointer = this.pointersForVisualization.getPointer(pointerChange.pointerIndex);
            var toIndex = -1;
            if (pointerChange.hasOwnProperty('nodeReference'))
                toIndex = current.getLinkedListForStep().getNodeLocation(pointerChange.To);
            else if (pointerChange.hasOwnProperty('nodePosition'))
                toIndex = current.getLinkedListForStep().getNode(pointerChange.To);
            this.movePointer(pointerChange.pointerIndex, toIndex, pointerChange.To);
            this.visualizer.step();
            pointerChange = null; //done
        }
        //remove every node from the linked list
        for (var i = 0; i < removedNodes.length; i++) {
            var node = removedNodes[i];
            var nodeIndex = current.getLinkedListForStep().getNodeLocation(node.getReference());
            if (nodeIndex != 0) { //means that the node is in the middle of the list. So, we need to visualize the remove
                var parentNode = this.JsavLinkedList.get(nodeIndex - 1);
                parentNode.edgeToNext().hide();
                var edge = this.JsavLinkedList.connection(parentNode.element, this.JsavLinkedList.get(nodeIndex + 1).element);
                edge.show();
                this.visualizer.umsg("change the next of the node with value " + current.getLinkedListForStep().getNode(nodeIndex - 1).getData() + " to point to the node with value " +
                    current.getLinkedListForStep().getNode(nodeIndex + 1).getData());
                this.visualizer.step();
                edge.hide();
            }
            this.visualizer.umsg('remove node with data equals ' + current.getLinkedListForStep().getNode(nodeIndex).getData());
            this.JsavLinkedList.remove(nodeIndex);
            //Update the current Linked List stpe nodes
            current.getLinkedListForStep().removeAt(nodeIndex);
            this.JsavLinkedList.layout();
            if (i !== removedNodes.length - 1)
                this.visualizer.step();
        }
        //correct the indices of pointers pointee location. The difference occurred due to deleted nodes
        this.correctPointersForVisualization(next);
    }
/**
     * There is a change in the number of nodes inside the list. So, we need to detect, apply and visualize the change
     * @param {VisualizationStep} current the current visualization step
     * @param {VisualizationStep} next the next visualization step
     * @param {Hash} changeObject Hash table that contains the changes to be applied on list nodes
     * @param {Hash} pointerChange Hash table that contains the changes to be applied on pointers
     */
There is a change in the number of nodes inside the list. So, we need to detect, apply and visualize the change
@param {VisualizationStep} current the current visualization step
@param {VisualizationStep} next the next visualization step
@param {Hash} changeObject Hash table that contains the changes to be applied on list nodes
@param {Hash} pointerChange Hash table that contains the changes to be applied on pointers
There is a change in the number of nodes inside the list . So we need to detect apply and visualize the change @param { VisualizationStep } current the current visualization step @param { VisualizationStep } next the next visualization step @param { Hash } changeObject Hash table that contains the changes to be applied on list nodes @param { Hash } pointerChange Hash table that contains the changes to be applied on pointers
remove_nodesFromTheList(current, next, changeObject, pointerChange) {
        var removedNodes = current.getLinkedListForStep().LinkedListNodes.
        filter(comparer(next.getLinkedListForStep().LinkedListNodes));
        if (changeObject.To === 0) 
        {
            for (var i = 0; i < this.pointersForVisualization.size(); i++) 
                this.nullifyPointer(i);
            for (i = current.getLinkedListForStep().size() - 1; i >= 0; i--) {
                this.JsavLinkedList.remove(i);
                current.getLinkedListForStep().removeAt(i);
            }
            return;
        }
        var after = false;
        if(pointerChange!== null){
        var oldPointerPointeeIndex = pointerChange.nodePosition;
        var differenceInIndices = pointerChange.nodePosition - pointerChange.To;
        for (var i = 0; i < removedNodes.length; i++) {
            var node = removedNodes[i];
            var nodeIndex = current.getLinkedListForStep().getNodeLocation(node.getReference());
            if (nodeIndex < oldPointerPointeeIndex)
                differenceInIndices--;
        }
    }
        if (pointerChange !== null && differenceInIndices !== 0) {
            var pointer = this.pointersForVisualization.getPointer(pointerChange.pointerIndex);
            var toIndex = -1;
            if (pointerChange.hasOwnProperty('nodeReference'))
                toIndex = current.getLinkedListForStep().getNodeLocation(pointerChange.To);
            else if (pointerChange.hasOwnProperty('nodePosition'))
                toIndex = current.getLinkedListForStep().getNode(pointerChange.To);
            this.movePointer(pointerChange.pointerIndex, toIndex, pointerChange.To);
            this.visualizer.step();
            pointerChange = null; 
        }
        for (var i = 0; i < removedNodes.length; i++) {
            var node = removedNodes[i];
            var nodeIndex = current.getLinkedListForStep().getNodeLocation(node.getReference());
            if (nodeIndex != 0) { 
                var parentNode = this.JsavLinkedList.get(nodeIndex - 1);
                parentNode.edgeToNext().hide();
                var edge = this.JsavLinkedList.connection(parentNode.element, this.JsavLinkedList.get(nodeIndex + 1).element);
                edge.show();
                this.visualizer.umsg("change the next of the node with value " + current.getLinkedListForStep().getNode(nodeIndex - 1).getData() + " to point to the node with value " +
                    current.getLinkedListForStep().getNode(nodeIndex + 1).getData());
                this.visualizer.step();
                edge.hide();
            }
            this.visualizer.umsg('remove node with data equals ' + current.getLinkedListForStep().getNode(nodeIndex).getData());
            this.JsavLinkedList.remove(nodeIndex);
            current.getLinkedListForStep().removeAt(nodeIndex);
            this.JsavLinkedList.layout();
            if (i !== removedNodes.length - 1)
                this.visualizer.step();
        }
        this.correctPointersForVisualization(next);
    }
remove_nodesFromTheList ( current , next , changeObject , pointerChange ) { var removedNodes = current . getLinkedListForStep ( ) . LinkedListNodes . filter ( comparer ( next . getLinkedListForStep ( ) . LinkedListNodes ) ) ; if ( changeObject . To === 0 ) { for ( var i = 0 ; i < this . pointersForVisualization . size ( ) ; i ++ ) this . nullifyPointer ( i ) ; for ( i = current . getLinkedListForStep ( ) . size ( ) - 1 ; i >= 0 ; i -- ) { this . JsavLinkedList . remove ( i ) ; current . getLinkedListForStep ( ) . removeAt ( i ) ; } return ; } var after = false ; if ( pointerChange !== null ) { var oldPointerPointeeIndex = pointerChange . nodePosition ; var differenceInIndices = pointerChange . nodePosition - pointerChange . To ; for ( var i = 0 ; i < removedNodes . length ; i ++ ) { var node = removedNodes [ i ] ; var nodeIndex = current . getLinkedListForStep ( ) . getNodeLocation ( node . getReference ( ) ) ; if ( nodeIndex < oldPointerPointeeIndex ) differenceInIndices -- ; } } if ( pointerChange !== null && differenceInIndices !== 0 ) { var pointer = this . pointersForVisualization . getPointer ( pointerChange . pointerIndex ) ; var toIndex = - 1 ; if ( pointerChange . hasOwnProperty ( 'nodeReference' ) ) toIndex = current . getLinkedListForStep ( ) . getNodeLocation ( pointerChange . To ) ; else if ( pointerChange . hasOwnProperty ( 'nodePosition' ) ) toIndex = current . getLinkedListForStep ( ) . getNode ( pointerChange . To ) ; this . movePointer ( pointerChange . pointerIndex , toIndex , pointerChange . To ) ; this . visualizer . step ( ) ; pointerChange = null ; } for ( var i = 0 ; i < removedNodes . length ; i ++ ) { var node = removedNodes [ i ] ; var nodeIndex = current . getLinkedListForStep ( ) . getNodeLocation ( node . getReference ( ) ) ; if ( nodeIndex != 0 ) { var parentNode = this . JsavLinkedList . get ( nodeIndex - 1 ) ; parentNode . edgeToNext ( ) . hide ( ) ; var edge = this . JsavLinkedList . connection ( parentNode . element , this . JsavLinkedList . get ( nodeIndex + 1 ) . element ) ; edge . show ( ) ; this . visualizer . umsg ( "change the next of the node with value " + current . getLinkedListForStep ( ) . getNode ( nodeIndex - 1 ) . getData ( ) + " to point to the node with value " + current . getLinkedListForStep ( ) . getNode ( nodeIndex + 1 ) . getData ( ) ) ; this . visualizer . step ( ) ; edge . hide ( ) ; } this . visualizer . umsg ( 'remove node with data equals ' + current . getLinkedListForStep ( ) . getNode ( nodeIndex ) . getData ( ) ) ; this . JsavLinkedList . remove ( nodeIndex ) ; current . getLinkedListForStep ( ) . removeAt ( nodeIndex ) ; this . JsavLinkedList . layout ( ) ; if ( i !== removedNodes . length - 1 ) this . visualizer . step ( ) ; } this . correctPointersForVisualization ( next ) ; }
There is a change in the number of nodes inside the list.
There is a change in the number of nodes inside the list .
//means that the list will be null //make all pointers to null //Update the current Linked List stpe nodes //We need to determine if we should remove first or move the pointer first //if the pointer pointes to a node after a removed node so it is normal to see a change in the index of the node //if it points to a node before the removed one so we should apply the pointer change //done //remove every node from the linked list //means that the node is in the middle of the list. So, we need to visualize the remove //Update the current Linked List stpe nodes //correct the indices of pointers pointee location. The difference occurred due to deleted nodes