Skip to content

Instantly share code, notes, and snippets.

Created September 24, 2013 12:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/6683768 to your computer and use it in GitHub Desktop.
Save anonymous/6683768 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <conio.h>
#include <time.h>
#include <vector>
#include <string>
#include <time.h>
#include "sort.h"
using namespace std;
void getSequence(vector<int> &Seq)
{
int x = 0;
for ( int i = 0; ; i++)
{
cin >> x;
if (x==-1) break; //исправить
Seq.push_back(x);
}
}
void test(vector<int> &Seq,int iterations)
{ //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
cout<<"BubbleSorted sequence\n";
clock_t time_start_bubble=clock();
vector<int> bubbleSeq(Seq.size());
for (int i = 0; i<iterations; i++)
{
bubbleSeq=Seq;
bubbleSort(bubbleSeq.data(),Seq.size());
}
for (vector<int>:: iterator it = bubbleSeq.begin();it!=bubbleSeq.end();it++)
{
cout << *it << ' ';
};
cout << endl;
clock_t time_end_bubble=clock();
cout << (double)(time_end_bubble - time_start_bubble) / CLOCKS_PER_SEC<< "ms\n";
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
cout<<"ShellSorted sequence\n";
clock_t time_start_shell=clock();
vector<int> shellSeq(Seq.size());
for (int i = 0; i<iterations; i++)
{
shellSeq=Seq;
shellSort(shellSeq.data(),Seq.size());
}
for (vector<int>:: iterator it = shellSeq.begin();it!=shellSeq.end();it++)
{
cout << *it << ' ';
};
cout << endl;
clock_t time_end_shell=clock();
cout << (double)(time_end_shell - time_start_shell) / CLOCKS_PER_SEC<< "ms\n";
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
cout<<"QuickSorted sequence\n";
clock_t time_start_quick=clock();
vector<int> quickSeq(Seq.size());
for (int i = 0; i<iterations; i++)
{
quickSeq = Seq;
quickSort(quickSeq.data(),0,Seq.size());
}
for (vector<int>:: iterator it = quickSeq.begin();it!=quickSeq.end();it++)
{
cout << *it << ' ';
};
cout << endl;
clock_t time_end_quick=clock();
cout << (double)(time_end_quick - time_start_quick) / CLOCKS_PER_SEC<< "ms\n";
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
cout<<"HeapSorted sequence\n";
clock_t time_start_heap=clock();
vector<int> heapSeq(Seq.size());
for (int i = 0; i<iterations; i++)
{
heapSeq=Seq;
heapSort(heapSeq.data(),Seq.size());
}
for (vector<int>:: iterator it = heapSeq.begin();it!=heapSeq.end();it++)
{
cout << *it << ' ';
};
cout << endl;
clock_t time_end_heap=clock();
cout << (double)(time_end_heap - time_start_heap) / CLOCKS_PER_SEC<< "ms\n";
}
int main ()
{
int iterations = 0;
vector <int> sequence;
cout << "Input your sequence, -1 to stop\n";
getSequence (sequence);
cout << "Input number of iterations\n";
cin >> iterations;
test(sequence,iterations);
getch();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment