Witam
Jak w temacie, uruchamia sie pozwala wpisac (po nacisnieciu 5) ilosc liczb do sortowania a potem nie reaguje na nic:(
Ilosc liczb ograniczona do 14000, program ma sluzyc do pokazania roznic w szybkosci sortowania roznymi metodami.
Srodowisko dev c++ 5.2.0.3.
Czy ktos wie dlaczego program sie wiesza?
Jesli takie problemy to nie to forum, przepraszam, prosze o wyrozumialosc dla poczatkujacego i informacje jakie forum bylo by najlepsze.
#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <dos.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <time.h>
#include <windows.h>
using namespace std;
int o;
int i,ile;
int tab[14001],tab1[14001];
char c;
class sortowania
{
public:
void quick_sort(int po, int r);
void sortbombe();
void insert();
void prostewybieranie();
}Ob1;
void sortowania::quick_sort(int po, int r)
{
int i,j,x,bufor;
i=po;
j=r;
x=tab[(po+r)/2];
do
{
while(tab[i]<x)
i=i++;
while(x<tab[j])
j=j--;
if(i<=j)
{
bufor=tab[i];
tab[i]=tab[j];
tab[j]=bufor;
i=i++;
j=j--;
}
}
while(i<=j);
if(po<j) quick_sort(po,j);
if(i<r) quick_sort(i,r);
}
void sortowania::sortbombe()
{
int j,x,x3;
clock_t start,end;
start=clock();
for (i=2;i<=ile;i++)
{
for(j=ile; j>=i; j--)
if(tab[j--]>tab[j])
{
x3=tab[j--];
tab[j--]=tab[j];
tab[j]=x3;
}
}
end=clock();
printf("\n czas sortowania babelkowego: %f ms\n", (100.0*(end-start))/CLK_TCK);
while(kbhit())
c=getch();
while(!kbhit());
}
void sortowania::insert()
{
clock_t start, end;
int x,j;
start=clock();
for(i=2; i<=ile; i++)
{
x=tab[i];
j=j--;
while((j>0)&&(tab[j]>x))
{
tab[j+1]=tab[j];
j=j--;
}
tab[j+1]=x;
}
end=clock();
printf("\n czas sortowania insert : %f ms \n", (100.0*(end-start))/CLK_TCK);
while(kbhit())
c=getch();
while(!kbhit());
}
void sortowania::prostewybieranie()
{
clock_t start,end;
int x,j,k;
start=clock();
for (i=1; i<=ile; i++)
{
k=i;
x=tab[i];
for(j=i; j<=ile; j++)
if (tab[j]<x)
{
k=j;
x=tab[j];
}
tab[k]=tab[i];
tab[i]=x;
}
end=clock();
printf("\nczas sortowania przes proste wybieranie: %fms\n",(100.0*(end-start))/CLK_TCK);
while(kbhit())
c=getch();
while(!kbhit());
}
//------------------------------------------
class reszta : public sortowania
{
public:
void ile_liczb();
void pokaztab();
void liczby();
void kopia();
reszta();
~reszta();
}Ob2;
reszta::~reszta()
{ printf("Ponownie wybierz");
getchar();
}
void reszta::ile_liczb()
{
printf("Podaj ile liczb posortować?\n");
scanf("\d", &ile);
}
//------------------------------------------
void reszta::pokaztab()
{
system("cls");
//clrscr();
for (i=1;1<=ile;i++)
printf("%d ",tab[i]);
while(kbhit())
c=getch();
while(!kbhit());
}
//------------------------------------------
void reszta::liczby()
{
srand((unsigned)time(NULL));
// srand(12000);
printf("\n\ngeneruje liczby - prosze czekac!\n");
for(i=1;i<=ile;i++)
{
tab[i]=rand()%5000;
tab1[i]=tab[i];
}
printf("liczby wygenerowane:\n");
printf("Nascisnij cos\n");
while (kbhit())
c=getch();
while (!kbhit());
}
///-----------------------------------------
void reszta::kopia()
{
for(i=1;i<=ile;i++)
tab[i]=tab1[i];
}
reszta::reszta()
{
clock_t start,end;
do
{
system("cls");
printf("wybierz jakies sortowanie\n");
printf("1-babelkowe\n");
printf("2-insert\n");
printf("3-wybieranie\n");
printf("4-wszystkie\n");
printf("5-definiowanie tablicy\n");
printf("6-guick sort\n");
printf("7-koniec\n");
c=getch();
switch(c)
{
case'1':kopia();
pokaztab();
Ob1.sortbombe();
pokaztab();
break;
case'2':kopia();
pokaztab();
Ob1.insert();
pokaztab();
break;
case'3':kopia();
pokaztab();
Ob1.prostewybieranie();
pokaztab();
break;
case'4':kopia();
Ob1.sortbombe();
liczby();
Ob1.insert();
liczby();
Ob1.prostewybieranie();
break;
case'5':ile_liczb();
liczby();
break;
case'6':kopia();
pokaztab();
start=clock();
Ob1.quick_sort(1,ile);
end=clock();
printf("\n czas sortowania quick_sort: %f ms\ n", (100.0 *(end-start))/CLK_TCK);
while(kbhit())
c=getch();
while(!kbhit());
pokaztab();
break;
}
while(c!=7);
}
while(!kbhit());
}
int main ()
{
reszta ();
return 0;
system ("PAUSE");
}
Pozdrawiam