Advertisement
Guest User

Untitled

a guest
Nov 20th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. void wys(int tab[]){
  5. for(int i=0;i<10;i++){
  6. cout << tab[i] << " ";
  7. }
  8. cout << endl;
  9. }
  10.  
  11. int main(){
  12. int tab [] = {5,10,4,6,3,7,9,23,1,77};
  13. int n = 10;
  14. int w = 0;
  15. wys(tab);
  16. int current;
  17. int otherIndex;
  18. for(int i=1; i < n;i++){
  19. current= tab[i];
  20. otherIndex = i;
  21. w++;
  22. while(otherIndex > 0 && current < tab[otherIndex -1]){
  23. tab[otherIndex] = tab[otherIndex -1];
  24. otherIndex--;
  25. w++;
  26. }
  27. tab[otherIndex] = current;
  28. }
  29. wys(tab);
  30. cout << "Algorytm wykonal sie:" << w << " razy";
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement