際際滷

際際滷Share a Scribd company logo
Universitatea de Stat din Republica Moldova
Facultatea de Matematica si Informatica
Specialitatea Informatica(E)
Laboratorul 1
la SDMP.
Tema: Algoritmi de cutare.
Scris de:Moraru Igor,grupa I21
Verificat de: VERIF. LECTOR,MAGISTRU IN INFORM BITCOVSCHI LUCIA
Chiinu 2014
Considerai teoretice
Prin structura de date abstract (SDA), sau pur i simplu structura de date
(SD), vom 樽n釘elege o totalitate de reguli i restric釘ii ce reflect
legturile existente 樽ntre pr釘ile separate de date i prin care pr釘ile
acestea se unesc 樽ntr-un singur tot.
Sortarea este opera釘ia de aranjare a elementelor unui vector dup valoarea
cheilor, pentru care este definit rela釘ia de ordine i datorit careea se
poate efectua mai rapid cautarea unui element.
Varianta 4.
S se implementeze c樽teva metode de sortare i s se efectueze sortarea
dup c樽mpul
cheie din fiierul textual, iar pentru fiecare metod de sortare s se
efectueze
urmtoarele:
- S se analizeze complexitatea teoretic i complexitatea practic a
metodelor de sortare
- De descris algoritmul metodei de sortare pe pai.
LISTINGUL
#include <conio.h>
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>
#include <dos.h>
//*abstract class ELEM
using namespace std;
class elem {
public:
virtual int fscanf_el(FILE * f)=0;
virtual int show(const char * opening, const char * ending)=0;
virtual int free()=0;
int operator >(elem &) {
error("Error should overide operator ">"!n");
return 0;
}
int operator <(elem &) {
error("Error should overide operator "<"!n");
return 0;
}
int operator >=(elem &) {
error("Error should overide operator ">="!n");
return 0;
}
int operator <=(elem &) {
error("Error should overide operator "<="!n");
return 0;
}
int operator ==(elem &) {
error("Error should overide operator "=="!n");
return 0;
}
int operator !=(elem &) {
error("Error should overide operator "!="!n");
return 0;
}
protected:
void error(char * message) {
cout << message;
cout << "press any key to fin....n";
getch();
exit(1);
}
};
//class Carte
class Carte
{
public:
int id;
char Nume_A[25];
char Prenume[25];
char Titlu_C[30];
float pret;
Carte()
{
id=0;
Nume_A[0]='0';
Prenume[0]='0';
Titlu_C[0]='0';
pret=0.0;
};
void setFirma(char* f) {
strcpy(firma,f);
}
void setModel(char* n) {
strcpy(model, n);
}
void setRam(int a) {
ram=a;
}
void setHdd(int i) {
hdd = i;
}
void setOs(char* i) {
strcpy(os,i);
}
char* getFirma() {
return firma;
}
char* getModel() {
return model;
}
int getRam() {
return ram;
}
int getHdd() {
return hdd;
}
char* getOs() {
return os;
}
int fscanf_el(FILE * f) {
return fscanf(f,"%s%s %i %i %s
%f",firma,model,&ram,&hdd,os,&pret);
}
void virtual show() {
cout<<firma<<" "<<model<<" "<<ram<<" "<<hdd<<"
"<<os<<" "<<pret<<endl;
}
virtual int free()
{
return model[0]=='0';
}
int operator > (Product& e2)
{
return strcmp(model, e2.model)>0 ? 1 : 0;
}
int operator < (Product& e2)
{
return strcmp(model, e2.model)<0 ? 1 : 0;
}
/*
int operator <=(Product &e2) {
return (this->code <= e2.code);
}
int operator >=(Product &e2) {
return (this->code >= e2.code);
}
*/
int operator ==(Product &e2) {
return strcmp(model, e2.model)==0 ? 1 : 0;
}
int operator !=(Product &e2) {
return strcmp(model, e2.model)!=0 ? 1 : 0;
}
};
template<class el> class tabel {
protected:
int n;
el t[50];
public:
tabel() {
n = 0;
}
tabel(char * file);
void sort();
void shell_sort();
void quickSort(int l, int r);
void selectsort(int l, int r);
void insertsort(int i, int j);
void downheap(long k, long n);
void heapsort(int l, int r);
void show();
protected:
void error(char *message) {
cout << message;
cout << "press any key to fin....n";
getch();
exit(1);
}
};
template<class el>
tabel<el>::tabel(char * file) {
FILE *pf;
pf = fopen(file, "rt");
n = 0;
while (!feof(pf))
if (t[n].fscanf_el(pf) > 0)
n++;
fclose(pf);
}
template<class el> void tabel<el>::show() {
for (int i = 0; i < n; i++) {
if (i % 20 == 0 && i > 0) {
cout << "nNajmite liubuiu klavishu dlea prodoljenian";
getch();
}
cout << (i + 1) << ". ";
t[i].show();
}
}
template<class el>
void tabel<el>::sort() {
int j, count = 0;
el aux;
for (int i = 0; i < n - 1; i++)
for (j = i; j < n; j++) {
if (strcmp(t[i].getModel(),t[j].getModel())>0)
{
aux = t[i];
t[i] = t[j];
t[j] = aux;
count++;
}
}
cout << "Slojnosti sortirovki BUBBLESORT= " << n * n << endl;
getch();
cout << "Koli4estvo perestanovok i sravnenii= " << j << endl;
}
template<class el>
void tabel<el>::selectsort(int l, int r) {
el tmp;
// struct time t1, t2;
int contor;
for (int i = 0; i < r; ++i) // i - nomer tekuschego shaga
{
int pos = i;
tmp = t[i];
for (int j = i + 1; j < r; ++j) // cikl vybora naimen'shego
elementa
{
if (t[j] < tmp) {
pos = j;
tmp = t[j];
}
}
t[pos] = t[i];
t[i] = tmp; // menyaem mestami naimen'shiy s a[i]
contor=i-1;
}
cout << "nSlojnosti sortirovki SELECTSORT= " << ((r * (r - 1)) / 2)
<< endl;
getch();
cout << "Koli4estvo perestanovok i sravnenii= " << (contor) << endl;
getch();
}
template<class el>
void tabel<el>::insertsort(int l, int r) {
el temp;
for (int i = 1, j; i < r; ++i) //cikl prohodov, i - nomer prohoda
{
temp = t[i];
for (j = i - 1; j >= 0 && t[j] > temp; --j) // poisk mesta elementa
v gotovoy posledovatel'nosti
t[j + 1] = t[j]; // sdvigaem element napravo, poka ne doshli
t[j + 1] = temp; // mesto naydeno, vstavit' element
}
cout << "nSlojnosti sortirovki INSERTSORT= " << ((r * (r - 1)) / 4)
<< endl;
getch();
}
template<class el>
void tabel<el>::quickSort(int l, int r)
{
el temp;
int i,x,j = r;i=l;
x=(i+j)/2;
while (i <= j){
///while (strcmp(t[i].getModel(), t[x])>0)
if(strcmp(t[x].getModel(),this->t[i].getModel())<0)
{ i++;}
//while (t[j].getModel() > x)
if (strcmp(t[x].getModel(),this->t[j].getModel())>0)
{ j--;}
if (i <= j) {
temp = t[i];
t[i] = t[j];
t[j] = temp;
i++;
j--;
}
}
if (i < r)
quickSort(i, r);
if (l < j)
quickSort(l, j);
}
template<class el>
void tabel<el>::downheap(long k, long n) {
// procedura proseivaniya sleduyuschego elementa
// Do procedury: a[k+1]...a[n] - piramida
// Posle: a[k]...a[n] - piramida
el new_elem;
long child;
new_elem = t[k];
while (k <= n / 2) // poka u a[k] est' deti
{
child = 2 * k;
if (child < n && t[child] < t[child + 1]) // vybiraem bol'shego
syna
child++;
if (new_elem > t[child])
break;
// inache
t[k] = t[child]; // perenosim syna naverh
k = child;
}
t[k] = new_elem;
}
template<class el>
void tabel<el>::heapsort(int l, int r) {
long i;
el temp;
// stroim piramidu
for (i = r / 2 - 1; i >= 0; --i)
downheap(i, r - 1);
// teper' a[0]...a[size-1] piramida
for (i = r - 1; i > 0; --i) {
// menyaem pervyy s poslednim
temp = t[i];
t[i] = t[0];
t[0] = temp;
// vosstanavlivaem piramidal'nost' a[0]...a[i-1]
downheap(0, i - 1);
}
cout << "nSlojnosti sortirovki HEAPSORT= " << (r * (log(r) /
log(2.0)))
<< endl;
getch();
cout << "Koli4estvo perestanovok i sravnenii= " << (r - 1) * 2 <<
endl;
getch();
}
int main() {
tabel<Product> gr("D:b.txt");
// struct time t1, t2;
Product pl;
char ch = 'n';
int id, i,r=50;
while (ch != 'y') {
cout << "n Soderjimoe faila: n";
gr.show();
cout << "nnt ~ ~Rezulitat sortirovki ~ ~" << endl;
getch();
// gettime(&t1);
// delay(50);
//gr.selectsort(0, 50);
//gr.insertsort(0,50);
/*
gr.quickSort(0, 50);
cout<<"nSlojnosti sortirovki QUICKSORT= "<<
(r*(log(r)/log(2.0))) <<endl;
getch();
cout<<"Koli4estvo perestanovok i sravnenii= "<<r<<endl;
getch();
*/
gr.heapsort(0,50);
//gr.sort();
// gettime(&t2);
// cout << "Vremea sortirovki: " << t2.ti_sec - t1.ti_sec <<
"secund "
// << t2.ti_hund - t1.ti_hund << "ms" << endl;
getch();
gr.show();
cout << "n Zavershiti? (Y/N) :";
ch = getch();
cout << endl;
}
}
Rezultatul:

More Related Content

What's hot (13)

Bai tap java
Bai tap javaBai tap java
Bai tap java
Man Bat
Cours de C++, en fran巽ais, 2002 - Cours 1.3
Cours de C++, en fran巽ais, 2002 - Cours 1.3Cours de C++, en fran巽ais, 2002 - Cours 1.3
Cours de C++, en fran巽ais, 2002 - Cours 1.3
Laurent BUNIET
丿舒弍仍仂仆 仗仂亠从亳仂于舒仆亳 2
丿舒弍仍仂仆 仗仂亠从亳仂于舒仆亳 2丿舒弍仍仂仆 仗仂亠从亳仂于舒仆亳 2
丿舒弍仍仂仆 仗仂亠从亳仂于舒仆亳 2
Constantin Kichinsky
EJEMPLOS DESARROLLADOS
EJEMPLOS DESARROLLADOSEJEMPLOS DESARROLLADOS
EJEMPLOS DESARROLLADOS
Darwin Durand
Rut
RutRut
Rut
Rudy Medina
Java 于亠仆舒 2013 仍亠从亳 6
Java 于亠仆舒 2013 仍亠从亳 6Java 于亠仆舒 2013 仍亠从亳 6
Java 于亠仆舒 2013 仍亠从亳 6
Technopark
Programs
ProgramsPrograms
Programs
Murali Kummitha
20150415 csharp6.0
20150415 csharp6.020150415 csharp6.0
20150415 csharp6.0
Ricardo Gonz叩lez
Toan pt.de021.2011
Toan pt.de021.2011Toan pt.de021.2011
Toan pt.de021.2011
B畉O H鱈
Toan pt.de022.2011
Toan pt.de022.2011Toan pt.de022.2011
Toan pt.de022.2011
B畉O H鱈
Cg lab cse-vii
Cg lab cse-viiCg lab cse-vii
Cg lab cse-vii
sajjan93
Writeup ctf online idsecconf 2017
Writeup ctf online idsecconf 2017Writeup ctf online idsecconf 2017
Writeup ctf online idsecconf 2017
idsecconf
Sis quiz
Sis quizSis quiz
Sis quiz
Clesio Veloso
Bai tap java
Bai tap javaBai tap java
Bai tap java
Man Bat
Cours de C++, en fran巽ais, 2002 - Cours 1.3
Cours de C++, en fran巽ais, 2002 - Cours 1.3Cours de C++, en fran巽ais, 2002 - Cours 1.3
Cours de C++, en fran巽ais, 2002 - Cours 1.3
Laurent BUNIET
丿舒弍仍仂仆 仗仂亠从亳仂于舒仆亳 2
丿舒弍仍仂仆 仗仂亠从亳仂于舒仆亳 2丿舒弍仍仂仆 仗仂亠从亳仂于舒仆亳 2
丿舒弍仍仂仆 仗仂亠从亳仂于舒仆亳 2
Constantin Kichinsky
EJEMPLOS DESARROLLADOS
EJEMPLOS DESARROLLADOSEJEMPLOS DESARROLLADOS
EJEMPLOS DESARROLLADOS
Darwin Durand
Java 于亠仆舒 2013 仍亠从亳 6
Java 于亠仆舒 2013 仍亠从亳 6Java 于亠仆舒 2013 仍亠从亳 6
Java 于亠仆舒 2013 仍亠从亳 6
Technopark
Toan pt.de021.2011
Toan pt.de021.2011Toan pt.de021.2011
Toan pt.de021.2011
B畉O H鱈
Toan pt.de022.2011
Toan pt.de022.2011Toan pt.de022.2011
Toan pt.de022.2011
B畉O H鱈
Cg lab cse-vii
Cg lab cse-viiCg lab cse-vii
Cg lab cse-vii
sajjan93
Writeup ctf online idsecconf 2017
Writeup ctf online idsecconf 2017Writeup ctf online idsecconf 2017
Writeup ctf online idsecconf 2017
idsecconf

Viewers also liked (16)

Accessing soft layer
Accessing soft layerAccessing soft layer
Accessing soft layer
carlito dizon
Idol power point
Idol power pointIdol power point
Idol power point
jsrcc
Ratio analiz
Ratio analizRatio analiz
Ratio analiz
Mahfuzur Rahman
Statistical process control training
Statistical process control trainingStatistical process control training
Statistical process control training
bilal183
Services marketing
Services marketingServices marketing
Services marketing
kevin Richard
Supply chain of Dabba Walas
Supply chain of Dabba WalasSupply chain of Dabba Walas
Supply chain of Dabba Walas
kevin Richard
Negotiable Instruments Act 1881
Negotiable Instruments Act 1881Negotiable Instruments Act 1881
Negotiable Instruments Act 1881
kevin Richard
Statistical process control technique with example - xbar chart and R chart
Statistical process control technique with example - xbar chart and R chartStatistical process control technique with example - xbar chart and R chart
Statistical process control technique with example - xbar chart and R chart
kevin Richard
ANG ALAMAT NG MAYA
ANG ALAMAT NG MAYA ANG ALAMAT NG MAYA
ANG ALAMAT NG MAYA
Barangay Suki
Indian contract act - Communication of offer and acceptance
Indian contract act - Communication of offer and acceptanceIndian contract act - Communication of offer and acceptance
Indian contract act - Communication of offer and acceptance
kevin Richard
Si PAGONG (PABULA)
Si PAGONG (PABULA)Si PAGONG (PABULA)
Si PAGONG (PABULA)
Barangay Suki
TRIPs agreement - WTO
TRIPs agreement - WTOTRIPs agreement - WTO
TRIPs agreement - WTO
kevin Richard
Accessing soft layer
Accessing soft layerAccessing soft layer
Accessing soft layer
carlito dizon
Idol power point
Idol power pointIdol power point
Idol power point
jsrcc
Statistical process control training
Statistical process control trainingStatistical process control training
Statistical process control training
bilal183
Services marketing
Services marketingServices marketing
Services marketing
kevin Richard
Supply chain of Dabba Walas
Supply chain of Dabba WalasSupply chain of Dabba Walas
Supply chain of Dabba Walas
kevin Richard
Negotiable Instruments Act 1881
Negotiable Instruments Act 1881Negotiable Instruments Act 1881
Negotiable Instruments Act 1881
kevin Richard
Statistical process control technique with example - xbar chart and R chart
Statistical process control technique with example - xbar chart and R chartStatistical process control technique with example - xbar chart and R chart
Statistical process control technique with example - xbar chart and R chart
kevin Richard
ANG ALAMAT NG MAYA
ANG ALAMAT NG MAYA ANG ALAMAT NG MAYA
ANG ALAMAT NG MAYA
Barangay Suki
Indian contract act - Communication of offer and acceptance
Indian contract act - Communication of offer and acceptanceIndian contract act - Communication of offer and acceptance
Indian contract act - Communication of offer and acceptance
kevin Richard
Si PAGONG (PABULA)
Si PAGONG (PABULA)Si PAGONG (PABULA)
Si PAGONG (PABULA)
Barangay Suki
TRIPs agreement - WTO
TRIPs agreement - WTOTRIPs agreement - WTO
TRIPs agreement - WTO
kevin Richard

Lab2 sdmp

  • 1. Universitatea de Stat din Republica Moldova Facultatea de Matematica si Informatica Specialitatea Informatica(E) Laboratorul 1 la SDMP. Tema: Algoritmi de cutare. Scris de:Moraru Igor,grupa I21 Verificat de: VERIF. LECTOR,MAGISTRU IN INFORM BITCOVSCHI LUCIA Chiinu 2014
  • 2. Considerai teoretice Prin structura de date abstract (SDA), sau pur i simplu structura de date (SD), vom 樽n釘elege o totalitate de reguli i restric釘ii ce reflect legturile existente 樽ntre pr釘ile separate de date i prin care pr釘ile acestea se unesc 樽ntr-un singur tot. Sortarea este opera釘ia de aranjare a elementelor unui vector dup valoarea cheilor, pentru care este definit rela釘ia de ordine i datorit careea se poate efectua mai rapid cautarea unui element. Varianta 4. S se implementeze c樽teva metode de sortare i s se efectueze sortarea dup c樽mpul cheie din fiierul textual, iar pentru fiecare metod de sortare s se efectueze urmtoarele: - S se analizeze complexitatea teoretic i complexitatea practic a metodelor de sortare - De descris algoritmul metodei de sortare pe pai. LISTINGUL #include <conio.h> #include <stdio.h> #include <iostream> #include <string.h> #include <math.h> #include <stdlib.h> #include <time.h> #include <dos.h> //*abstract class ELEM using namespace std; class elem { public: virtual int fscanf_el(FILE * f)=0; virtual int show(const char * opening, const char * ending)=0; virtual int free()=0; int operator >(elem &) { error("Error should overide operator ">"!n");
  • 3. return 0; } int operator <(elem &) { error("Error should overide operator "<"!n"); return 0; } int operator >=(elem &) { error("Error should overide operator ">="!n"); return 0; } int operator <=(elem &) { error("Error should overide operator "<="!n"); return 0; } int operator ==(elem &) { error("Error should overide operator "=="!n"); return 0; } int operator !=(elem &) { error("Error should overide operator "!="!n"); return 0; } protected: void error(char * message) { cout << message; cout << "press any key to fin....n"; getch(); exit(1); } }; //class Carte class Carte { public: int id; char Nume_A[25]; char Prenume[25]; char Titlu_C[30]; float pret; Carte() {
  • 4. id=0; Nume_A[0]='0'; Prenume[0]='0'; Titlu_C[0]='0'; pret=0.0; }; void setFirma(char* f) { strcpy(firma,f); } void setModel(char* n) { strcpy(model, n); } void setRam(int a) { ram=a; } void setHdd(int i) { hdd = i; } void setOs(char* i) { strcpy(os,i); } char* getFirma() { return firma; } char* getModel() { return model; } int getRam() { return ram; } int getHdd() { return hdd; } char* getOs() { return os; } int fscanf_el(FILE * f) { return fscanf(f,"%s%s %i %i %s %f",firma,model,&ram,&hdd,os,&pret); } void virtual show() {
  • 5. cout<<firma<<" "<<model<<" "<<ram<<" "<<hdd<<" "<<os<<" "<<pret<<endl; } virtual int free() { return model[0]=='0'; } int operator > (Product& e2) { return strcmp(model, e2.model)>0 ? 1 : 0; } int operator < (Product& e2) { return strcmp(model, e2.model)<0 ? 1 : 0; } /* int operator <=(Product &e2) { return (this->code <= e2.code); } int operator >=(Product &e2) { return (this->code >= e2.code); } */ int operator ==(Product &e2) { return strcmp(model, e2.model)==0 ? 1 : 0; } int operator !=(Product &e2) { return strcmp(model, e2.model)!=0 ? 1 : 0; } }; template<class el> class tabel { protected: int n; el t[50]; public: tabel() { n = 0; } tabel(char * file); void sort();
  • 6. void shell_sort(); void quickSort(int l, int r); void selectsort(int l, int r); void insertsort(int i, int j); void downheap(long k, long n); void heapsort(int l, int r); void show(); protected: void error(char *message) { cout << message; cout << "press any key to fin....n"; getch(); exit(1); } }; template<class el> tabel<el>::tabel(char * file) { FILE *pf; pf = fopen(file, "rt"); n = 0; while (!feof(pf)) if (t[n].fscanf_el(pf) > 0) n++; fclose(pf); } template<class el> void tabel<el>::show() { for (int i = 0; i < n; i++) { if (i % 20 == 0 && i > 0) { cout << "nNajmite liubuiu klavishu dlea prodoljenian"; getch(); } cout << (i + 1) << ". "; t[i].show(); } } template<class el> void tabel<el>::sort() { int j, count = 0;
  • 7. el aux; for (int i = 0; i < n - 1; i++) for (j = i; j < n; j++) { if (strcmp(t[i].getModel(),t[j].getModel())>0) { aux = t[i]; t[i] = t[j]; t[j] = aux; count++; } } cout << "Slojnosti sortirovki BUBBLESORT= " << n * n << endl; getch(); cout << "Koli4estvo perestanovok i sravnenii= " << j << endl; } template<class el> void tabel<el>::selectsort(int l, int r) { el tmp; // struct time t1, t2; int contor; for (int i = 0; i < r; ++i) // i - nomer tekuschego shaga { int pos = i; tmp = t[i]; for (int j = i + 1; j < r; ++j) // cikl vybora naimen'shego elementa { if (t[j] < tmp) { pos = j; tmp = t[j]; } } t[pos] = t[i]; t[i] = tmp; // menyaem mestami naimen'shiy s a[i] contor=i-1; } cout << "nSlojnosti sortirovki SELECTSORT= " << ((r * (r - 1)) / 2) << endl; getch(); cout << "Koli4estvo perestanovok i sravnenii= " << (contor) << endl; getch();
  • 8. } template<class el> void tabel<el>::insertsort(int l, int r) { el temp; for (int i = 1, j; i < r; ++i) //cikl prohodov, i - nomer prohoda { temp = t[i]; for (j = i - 1; j >= 0 && t[j] > temp; --j) // poisk mesta elementa v gotovoy posledovatel'nosti t[j + 1] = t[j]; // sdvigaem element napravo, poka ne doshli t[j + 1] = temp; // mesto naydeno, vstavit' element } cout << "nSlojnosti sortirovki INSERTSORT= " << ((r * (r - 1)) / 4) << endl; getch(); } template<class el> void tabel<el>::quickSort(int l, int r) { el temp; int i,x,j = r;i=l; x=(i+j)/2; while (i <= j){ ///while (strcmp(t[i].getModel(), t[x])>0) if(strcmp(t[x].getModel(),this->t[i].getModel())<0) { i++;} //while (t[j].getModel() > x) if (strcmp(t[x].getModel(),this->t[j].getModel())>0) { j--;} if (i <= j) { temp = t[i]; t[i] = t[j]; t[j] = temp; i++; j--; } } if (i < r)
  • 9. quickSort(i, r); if (l < j) quickSort(l, j); } template<class el> void tabel<el>::downheap(long k, long n) { // procedura proseivaniya sleduyuschego elementa // Do procedury: a[k+1]...a[n] - piramida // Posle: a[k]...a[n] - piramida el new_elem; long child; new_elem = t[k]; while (k <= n / 2) // poka u a[k] est' deti { child = 2 * k; if (child < n && t[child] < t[child + 1]) // vybiraem bol'shego syna child++; if (new_elem > t[child]) break; // inache t[k] = t[child]; // perenosim syna naverh k = child; } t[k] = new_elem; } template<class el> void tabel<el>::heapsort(int l, int r) { long i; el temp; // stroim piramidu for (i = r / 2 - 1; i >= 0; --i) downheap(i, r - 1); // teper' a[0]...a[size-1] piramida for (i = r - 1; i > 0; --i) {
  • 10. // menyaem pervyy s poslednim temp = t[i]; t[i] = t[0]; t[0] = temp; // vosstanavlivaem piramidal'nost' a[0]...a[i-1] downheap(0, i - 1); } cout << "nSlojnosti sortirovki HEAPSORT= " << (r * (log(r) / log(2.0))) << endl; getch(); cout << "Koli4estvo perestanovok i sravnenii= " << (r - 1) * 2 << endl; getch(); } int main() { tabel<Product> gr("D:b.txt"); // struct time t1, t2; Product pl; char ch = 'n'; int id, i,r=50; while (ch != 'y') { cout << "n Soderjimoe faila: n"; gr.show(); cout << "nnt ~ ~Rezulitat sortirovki ~ ~" << endl; getch(); // gettime(&t1); // delay(50); //gr.selectsort(0, 50); //gr.insertsort(0,50); /* gr.quickSort(0, 50); cout<<"nSlojnosti sortirovki QUICKSORT= "<< (r*(log(r)/log(2.0))) <<endl; getch(); cout<<"Koli4estvo perestanovok i sravnenii= "<<r<<endl; getch(); */ gr.heapsort(0,50); //gr.sort(); // gettime(&t2);
  • 11. // cout << "Vremea sortirovki: " << t2.ti_sec - t1.ti_sec << "secund " // << t2.ti_hund - t1.ti_hund << "ms" << endl; getch(); gr.show(); cout << "n Zavershiti? (Y/N) :"; ch = getch(); cout << endl; } } Rezultatul: