Skip to content

how to visualize my js own file step by step your demeo worked fine i need work this y file see here arr variable what happening #246

Open
@Kezara666

Description

@Kezara666

i need see arr object what happening with debuging

function insertionSort(arr) {
    // Traverse through 1 to arr.length
    for (let i = 1; i < arr.length; i++) {
        // Current element to be inserted in the sorted portion
        let key = arr[i];
        
        // Move elements of arr[0..i-1] that are greater than key 
        // to one position ahead of their current position
        let j = i - 1;
        while (j >= 0 && arr[j] > key) {
            arr[j + 1] = arr[j];
            j--;
        }
        
        // Place the key in its correct position
        arr[j + 1] = key;
    }
    
    return arr;
}

// Example usage
const exampleArray = [64, 34, 25, 12, 22, 11, 90];
console.log("Original array:", exampleArray);
const sortedArray = insertionSort(exampleArray);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions