Mam problem z programem. Chodzi w nim aby wczytane z pliku znaki sortowal za pomaca sortowań Quicksort i Sosrowania przez zliczanie. Chciałem to zrobić zmieniając znaki na przyporzadkowane im cyfry w kodzie ASCII. O dziwo w programie podczas kompilacji nie wyskakuja bledy, jednak kompiluje sie czarny ekran. Próbowałem wielu zmian żadna nie daje efektu. Dołączam kod :
#include <iostream>
#include <iomanip>
#include <windows.h>
#include <string.h>
#include <conio.h>
#include <fstream>
#include <stdlib.h>
using namespace std;
struct str
{
string op;
int dep;
};
float Quicksort(str *tab1,str *tab2 ,int lewy,int prawy,int a)
{
float t;
float start,stop;
for(int i=0;i<100000000;i++)
for (int j=0;j<a;j++)
tab1[j].dep=tab2[j].dep;
start=GetTickCount();
int x;
int c=lewy;
int b=prawy;
int v=tab1[(lewy+prawy)/2].dep;
do
{
while (tab1[c].dep<v)
c++;
while (tab1[b].dep>v)
b--;
if (c<=b)
{
x=tab1[c].dep;
tab1[c].dep=tab1[b].dep;
tab1[b].dep=x;
c++;
b--;
}
} while (c<=b);
if (b>lewy) Quicksort (tab1,tab2,lewy, b,a);
if (c<prawy) Quicksort (tab1,tab2, c, prawy,a);
stop=GetTickCount();
t=((stop)-(start));
return t;
}
float sortowanieprzezzliczanie(str *tab1,str *tab2, int dl,int a)
{
float t2;
float start,stop;
int i, min, max;
for(int i=0;i<100000000;i++)
for (int j=0;j<a;j++)
tab1[j].dep=tab2[j].dep;
start=GetTickCount();
min = max = tab1[0].dep;
for(i = 1; i < dl; i++)
{
if (tab1[i].dep < min)
min = tab1 [i].dep;
else if (tab1 [i].dep > max)
max = tab1 [i].dep;
}
int d = max - min + 1;
int *b = (int *) malloc(d * sizeof(int));
for(i = 0; i < d; i++)
b[i] = 0;
for(i = 0; i < dl; i++)
b[ tab1[i].dep - min ]++;
int j, z = 0;
for(i = min; i <= max; i++)
for(j = 0; j < b[ i - min ]; j++)
tab1[z++].dep = i;
stop=GetTickCount();
t2=((stop)-(start));
return t2;
}
void czas(long t,long t2)
{
if(t<t2)
cout<<"Quicksort jest szybszy"<<endl;
if(t2<t)
cout<<"Sortowanie przez zliczanie jest szybsze"<<endl;
}
int poczatek(string nazwa)
{
int a=0;
int y=0;
string we;
ifstream plk(nazwa.c_str());
while(!plk.eof())
{
getline(plk,we);
if(we.size()!=0)
a++;
y++;
}
cout<<endl;
plk.close();
return a;
}
void wstep(str *tab1, str *tab2, int n, string nazwa)
{
int l;
string we;
ifstream plk(nazwa.c_str());
l=-1;
for(int x=0;x<n;x++)
{
tab1[x].op="";
tab2[x].op="";
}
while(!plk.eof())
{
getline(plk,we);
if(we.size()!=0)
{
l++;
if(l<n)
{
tab1[l].op=we;
tab2[l].op=tab1[l].op;
}
}
}
plk.close();
}
void dzialanie(str *tab1, str *tab2, str *tab3, string nazwa, int a)
{
int k=0;
int p;
string we;
ifstream plk(nazwa.c_str());
while(!plk.eof())
getline(plk,we);
if(we.size()!=0)
{
for(int j=0; j< we.size();j++)
{
p=static_cast<int>(we[j]);
for(int l=0;l<(we.size()- j);l++)
p=p+10;
tab1[j].dep+=p;
}
k++;
}
for (int i=0;i<a ;i++)
{
tab2[i].dep=tab1[i].dep;
tab3[i].dep=tab1[i].dep;
}
plk.close();
}
void druk1( str *tab1, int a)
{
for(int i=0; i<a;i++)
cout <<tab1[i].op << endl;
}
void druk2( str *tab1, int a)
{
for(int i=0; i<a;i++)
cout << tab1[i].dep << endl;
}
void zapis (str *tab1, string nazwa,int a)
{
ofstream plk(nazwa.c_str());
for(int i=0;i<a;i++)
plk<<tab1[i].op<<endl;
plk.close();
}
int main(int argc, char* argv[])
{
int a;
int lewy=0,prawy=128;
long t,t1;
string nw,nz;
nw="a.txt";
poczatek(nw);
a=poczatek(nw);
str *tab1,*tab2, *tab3;
wstep(tab1,tab2,a,nw);
druk1(tab2,a);
dzialanie(tab1,tab2,tab3,nw,a);
druk1(tab2,a);
Quicksort(tab1,tab2,lewy,prawy,a);
sortowanieprzezzliczanie(tab1,tab2, 128,a);
druk2(tab1,a);
cout<<endl;
druk2(tab2,a);
czas(t,t1);
delete []tab1;
delete []tab2;
delete []tab3;
return 0;
}
Byłbym bardzo wdzięczny, gdyby ktoś potrafił mi pomóc w uruchomieniu programu.
Pozdrawiam!
//q:poprawilem Ci formatowanie kodu, zebys mial w ogole jakies szanse:/</cpp>