I'm trying to print the number of comparisons made when doing an insertion sort and the program compiles without a problem but after being prompted to type in however many numbers are necessary, when I input numbers nothing happens.
Code:#include<iostream> using namespace std; #define MAX_LIST_LEN 100 int main(){ int n, // list length j, // loop control L, // index of maximum element in unsorted section a[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; int count = 0; for (int L = 2; L<n; L++){ while (L <= n) j = L; while (j>=2 )a[j]<a[j-1]; a [j] == a[j-1]; j = j-1; int L = L+1; while (L>=1&&++count&&a[j]<a[j-1] )cout << count << " "; return(0); } }



LinkBack URL
About LinkBacks


