Sorting Algorithms

Here is my program!
Couple of things i need help with, is finding:
1)number of comparisons for each sort(i'm doing something already, but i don't think it's correct.
2)number of interchanges.
3)also need to print 5 elements of array on each line.
If someone could help, i would very much appreciate it!

That's not bubble sort. Bubble Sort only swaps adjacent items and as such an item gradually moves over until it is in place. Since you're not swapping adjacent items, it's actually just moving the next best item directly into the same place repeatedly each loop.
The way you are counting the comparisons for that algorithm will work, however you're not counting the number of swaps as well. WHy don't you use that swap function that you're made right below it?
Note, bubble sort is not stupid. It is actually a good choice when there are fewer than about 8 items.

You're not counting comparisons at all in heap sort. You're also ignoring the count of the number of swaps. You need to actually do something with the return value the way you're got it written at the moment.

You're not attempting to count anything in quicksort, except the number of times it is called (always 1).

The best way to count these things is to sort objects instead of integers. The objects only need to hold an integer, but you can customise the less-than operator to count the comparisons. You can provide a swap method that counts how many times it is called as well. That way you wont need and kind of count++; inside the sorting algorithm at all.

My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger

Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

yes, i understand that i have to have counters, the only problem is where to place them?
i tried placing them under swaps and comparisons, but it doesn't give the right answer.

Any time your code is about to compare two items you'll need to increment the count, much like you are in your "bubbleSort" function.

But you have a more pressing problem to solve first. How do you plan on getting the number of comparisons and the number of swaps back to your main function? You can't return both from the sorting routines unless you use some kind of struct or a std::pair. You might be better off (for your ability level) to just declare the counts as global. Remember to zero them before calling each sort routine of course.
From then it's really quite simple. As your code is about to compare items, increment the number of comparisons. If the code is swapping items, then increment the swap count.

Like I said though, that isn't Bubble Sort, and the difference for that algorithm with almost sorted data vs random ordering is pretty marginal. The exact number of item comparisons for that method is 0.5*(n*n - n) in every case.

My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger

Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"