Ok so I have to write insertion sort but every time I compile it and run it and enter numbers to sort i get some crazy errors.

here is an example, I entered :2 3 4 1 5 and I got this output 2 -2.70464e+303 1 3 4

Im so confused on what to do

Here is my code so far:

any advice/help would greatly be appreciated

Code:#include<iostream> using namespace std; #define MAX_LIST_LEN 100 int main(void){ int n, // list length j, // loop control L, // index of rightmost element in unsorted section count; // Count comparisons double temp, // temporary storage list[MAX_LIST_LEN]; // array to be sorted // Get values for n and list. cout << "Enter list length (must be less than or equal to " << MAX_LIST_LEN << "): "; cin >> n; cout << "Enter " << n << " numbers:" << endl; for(j=0; j<n; j++){ cin >> list[j]; } // perform InsertionSort algorithm on list L=2; while(L<=n) { j=L; while(j>=2 && list[j]<list[j-1]){ temp = list[j]; list[j]=list[j-1]; list[j-1]=temp; j--; } L = L+1; } // Print out sorted list. for(j=0; j<n; j++){ cout << list[j] << " "; } cout << endl; return(0); }