Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SORTOWANIE BOMBELKOWE
- -------------------------------------------------------------------------------------------------------------------------
- #include <iostream>
- #include <cstdlib>
- #include <time.h>
- using namespace std;
- int bombelek(int s, int t[])
- {
- int a, b=0;
- for(int i=0; i<s-1; i++)
- {
- for(int j=0; j<s; j++)
- {
- if(j!=s-1)
- {
- if(t[j]>t[j+1])
- {
- a = t[j];
- t[j] = t[j+1];
- t[j+1] = a;
- }
- else {b++;}
- }
- }
- if(b==s-1) break;
- else b=0;
- }
- return* t;
- }
- int main()
- {
- int n;
- cin>>n;
- int bsort[n];
- srand(time(NULL));
- for(int i=0; i<n; i++)
- {
- bsort[i] = rand()%10;
- cout<<bsort[i]<<" ";
- }
- cout<<endl;
- int f = bombelek(n, bsort);
- for(int i=0; i<n; i++)
- {
- cout<<bsort[i]<<" ";
- }
- return 0;
- }
- -------------------------------------------------------------------------------------------------------------------------
- SELECT SORT
- -------------------------------------------------------------------------------------------------------------------------
- #include <iostream>
- #include <cstdlib>
- #include <time.h>
- using namespace std;
- int select(int s, int t[])
- {
- int MIN, y=0 , j, x;
- bool b;
- for(int i=0; i<s-1; i++)
- {
- MIN = t[i];
- b = false;
- for(j=i+1; j<s; j++)
- {
- if(t[j]<=MIN)
- {
- MIN = t[j];
- y = j;
- b = true;
- }
- }
- if(b == false) break;
- else swap(t[i], t[y]);
- }
- return *t;
- }
- int main()
- {
- int n;
- cin>>n;
- int ssort[n];
- srand(time(NULL));
- for(int i=0; i<n; i++)
- {
- ssort[i] = rand()%10+1;
- cout<<ssort[i]<<" ";
- }
- cout<<endl;
- select(n, ssort);
- cout<<endl;
- for(int i=0; i<n; i++)
- {
- cout<<ssort[i]<<" ";
- }
- return 0;
- }
- -------------------------------------------------------------------------------------------------------------------------
- INSERTION SORT
- -------------------------------------------------------------------------------------------------------------------------
- #include <iostream>
- #include <cstdlib>
- #include <time.h>
- using namespace std;
- int INSERT(int s, int t[])
- {
- int z;
- bool b;
- for(int i=0; i<s-1; i++)
- {
- for(int j=i+1; j<s; j++)
- {
- if(t[i] > t[j])
- {
- z = t[j];
- t[j] = t[i];
- t[i] = z;
- }
- }
- }
- return *t;
- }
- int main()
- {
- int n;
- cin>>n;
- int isort[n];
- srand(time(NULL));
- for(int i=0; i<n; i++)
- {
- isort[i] = rand()%10+1;
- cout<<isort[i]<<" ";
- }
- cout<<endl;
- INSERT(n, isort);
- cout<<endl;
- for(int i=0; i<n; i++)
- {
- cout<<isort[i]<<" ";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement