Help me sortarisma (metrisi sixnotitas)
Giorgos Keramidas
keramida at ceid.upatras.gr
Thu Jul 6 12:07:22 EEST 2006
On 2006-07-06 11:47, Giorgos Keramidas <keramida at ceid.upatras.gr> wrote:
> On 2006-07-06 11:46, Giorgos Keramidas <keramida at ceid.upatras.gr> wrote:
> > On 2006-07-06 10:28, Dimitris Mexis <m65 at vivodinet.gr> wrote:
> > > Xero oti polloi pali tha poun alla to vala se allo simio kai den exo kai
> > > poli megali adapokrisi, opote to anarto kai edo:
> > > [...]
> >
> > Opws exw ksanapei, alla arneisai na paradexteis akoma, prepei na
> > arxiseis na energopoieis ta warnings tou compiler sou kapoia stigmh.
> >
> > Dior8wse ta parakatw kai meta isws einai pio profanes pou einai to bug.
> > [...]
>
> Sorry, copy/paste error. Ta swsta warnings einai:
>
> mexis.cpp:1: warning: ISO C++ forbids declaration of `main' with no type
> [...]
Ena swsta indented, reformatted version tou programmatos einai attached.
Ta sxolia gia kathe grammh parakatw:
1 int
2 main(void)
3 {
Sto arxiko sou programma h main() den exei oute return type oute `void'.
Opws tha eides sta warnings, ayto den einai kalh idea.
4 stocks[recordscapm].capm.price = new float[tRec];
5 stocks[recordscapm].capm.grpprice = new float[tRec];
Pou akribws orizontai o typos tou `stocks'?
Ti einai to `recordscapm' kai pou orizetai?
Ti einai to `tRec' kai pou orizetai?
7 stocks[recordscapm].capm.timebuy = new string[tRec];
8 stocks[recordscapm].capm.freq = new float[tRec];
Ta idia.
10 FreqArrayCount(stocks[recordscapm].capm.grpprice, stocks[recordscapm].capm.freq,
11 stocks[recordscapm].capm.elements,
12 stocks[recordscapm].capm.grpelements);
13 return 0;
To return eleipe sto arxiko programma. Se `hosted' ylopoihseis ths C++
ayto den einai aparaithta kako. Se embedded C++ programmata omws (opws
p.x. kati pou mporei argotera na treksei se Symbian), mporei na exei
idiaitero endiaferon kai poly plaka to apotelesma otan h main()
epistrefei undefined pragmata sto systhma.
14 }
15
16 void
17 FreqArrayCount(float *&matrix, float *&freq, size_t elements, size_t & grpelements)
18 {
Giati pernas ena `pointer' se reference? Eisai sigouros oti ayto thes?
An nai, giati meta to xrhsimopoieis ws aplo 'array'?
19 size_t i, k, count;
20
21 SortPrices(matrix, elements);
22
23 for (i = 0; i < elements; i++) {
24 count = 0;
25 for (k = 1; k < elements; k++) {
26 if ((matrix[i] != NULL) && (matrix[k] != NULL)) {
27 if (fabs(matrix[i] - matrix[k]) <= PRECISION) {
28 count++;
29 freq[i] = count;
30 }
31 }
32 }
33 }
Afou tha diatrekseis olo ton pinaka matrix[] etsi ki alliws, ti nohma
exei na kaneis pre-sort ton pinaka?
Epishs, to exeis dei oti to parapanw tha prospelasei N, N-1, ... 1
stoixeia tou pinaka, me apotelesma o xronos pou xreiazesai gia na
teleioseis na einai ths takshs tou (N * N)?
Eisai sigouros oti de 8a htan pio aplo na metrhseis me diaforetiko tropo
poses fores emfanizetai ena stoixeio ston pinaka?
Anti na kaneis, p.x. gia ton pinaka:
[ 10.0 10.0 10.0 10.0 10.0 10.0 10.0 10.0 10.0 10.0 10.0 10.0 ]
12 fores thn idia douleia, tha mporouses na sxediaseis th domh sou etsi
pou me ena perasma ston pinaka na exeis ena hash/map/kati-allo pou na
exei oles tis syxnothtes me th mia, se ligotero xrono kai pithanon me
ligotero kostos se xwro.
35 GroupBy(matrix, freq, elements, grpelements);
Ki ayto to function 8a htan pleon axrhsto.
36 }
37
38 void
39 SortPrices(float *&array, size_t size)
40 {
41 float min;
42 int b;
43
44 /* This loop goes through the whole array */
Ta profanh kai axrhsta sxolia einai kalytera na leipoun. Einai axrhsta,
einai profanh, den boh8ane se tipota thn katanohsh tou programmatos apo
kapoion pou to diabazei kai spataloun xwro.
46 for (int a = 0; a < size - 1; a++) {
47 /*
48 * Find the minimum element in array[a+1] ... array[size-1]
49 */
50 b = a;
51 min = array[b];
52 for (int j = a + 1; j < size; j++) {
53 if (array[j] < min) {
54 b = j;
55 min = array[b]; /* ...and if yes, then get it */
56 }
57 }
58 /*
59 * Now swap array[a] with the minimum element.
60 */
61 array[b] = array[a];
62 array[a] = min;
63 }
64 }
To arxiko programma parapanw eixe sxolia toy styl:
min = array[b]; //Get the current value
//...and check if any of the rest numbers is lower
for(int j = a+1; j<size; j++){
if( array[j]< min ){
b = j;
min = array[b]; //...and if yes, then get it
Einai axrhsto kai enoxlhtiko na epanalambaneis me logia ayto pou mporei
na dei kapoios apla koitazontas to source. Ta epoikodomhtika sxolia den
einai ayta pou ksanalene akribws ti kanei o kwdikas, alla ayta pou
ekshgoun *GIATI* kanei ayto pou kanei, giati to kanei *ETSI* ki oxi
alliws, klp.
66 void
67 GroupBy(float *&matrix, float *&freq, size_t & elements, size_t & grpelements)
68 {
Asxoliasto function, akribws epeidh einai axrhsto kai apaisia grammeno.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mexis.cpp
Type: text/x-c++src
Size: 2521 bytes
Desc: not available
URL: <http://lists.hellug.gr/pipermail/linux-greek-users/attachments/20060706/8e84cd23/attachment.cpp>
More information about the Linux-greek-users
mailing list