Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <iostream>
- #include <stdio.h>
- #include <math.h>
- #include <stdlib.h>
- #include <cstdio>
- #include <vector>
- #include <ctime>
- using namespace std;
- template <class Type>
- void my_sort( vector <Type> & mass){
- int a;
- for(int i=1;i<mass.size();i++){
- for(int j=i-1;j>=0;j--){
- if(mass[i]<mass[j]){
- a = mass[i];
- mass[i]=mass[j];
- mass[j]=a;
- i--;
- }
- }
- }
- }
- template <class Type>
- void cout_mass(vector <Type> & mass)
- {
- cout<<"[";
- if(mass.size()>20){
- for(int i =0;i<20;i++){
- cout<<mass[i]<<" ";
- }
- cout<<" ...]"<<endl;
- }
- else{
- for(int i =0;i<mass.size();i++){
- cout<<mass[i]<<" ";
- }
- cout<<"]"<<endl<<endl;
- }
- }
- int main(){
- setlocale(LC_ALL,"Russian");
- vector <int>arr;
- vector <int>avto;
- cout<<"Выберите, как будет заполняться вектор:"<<endl<<"1 - Вручную "<<endl
- <<"2 - автоматически "<<endl<<"3 - автоматически с малым диапазоном значений"<<endl<<"Ваш выбор: ";
- char r;
- cin>>r;
- srand(time(0));
- switch(r)
- {
- case '1' :{
- cout<<"Выберите количество элементов массива --> n = ";
- int n;
- cin>>n;
- for(int i=0;i<n;i++)
- {
- int m;
- //cout<<"mass["<<i<<"] = ";
- cin >>m;
- arr.push_back(m);
- avto.push_back(m);
- }
- break;
- }
- case '2' :{
- cout<<"Выберите количество элементов массива --> n = ";
- int n;
- cin>>n;
- for(int i=0;i<n;i++)
- {
- int m = rand()%n;
- arr.push_back(m);
- avto.push_back(m);
- }
- break;
- }
- case '3' :{
- cout<<"Выберите количество элементов массива --> n = ";
- int n;
- cin>>n;
- for(int i=0;i<n;i++)
- {
- int m = rand()%20;
- arr.push_back(m);
- avto.push_back(m);
- }
- break;
- }
- default : {
- cout<<"error"<<endl;
- exit(0);}
- }
- cout_mass(arr);
- cout_mass(avto);
- cout<<endl<<endl;
- clock_t time1,time2;
- time1 = clock();
- my_sort(arr);
- time2 = clock();
- cout_mass(arr);
- cout<<"time = "<<time2 - time1<<endl<<endl;
- time1 = clock();
- sort(avto.begin(),avto.end());
- cout_mass(avto);
- cout<<"time2 = "<<time2 - time1<<endl;
- system("pause");
- return 0;}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement