Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void wys(int tab[]){
- for(int i=0;i<10;i++){
- cout << tab[i] << " ";
- }
- cout << endl;
- }
- int main(){
- int tab [] = {5,10,4,6,3,7,9,23,1,77};
- int n = 10;
- int w = 0;
- wys(tab);
- int current;
- int otherIndex;
- for(int i=1; i < n;i++){
- current= tab[i];
- otherIndex = i;
- w++;
- while(otherIndex > 0 && current < tab[otherIndex -1]){
- tab[otherIndex] = tab[otherIndex -1];
- otherIndex--;
- w++;
- }
- tab[otherIndex] = current;
- }
- wys(tab);
- cout << "Algorytm wykonal sie:" << w << " razy";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement