23 45000
22 3000
20 4500
The first column is the security price and the second the volume. It's to be
sorted this way:
3000 4500 45000
23 x
22 x
20 x
This is a type of supply/demand data format. In this little bit of data it
can be seen that there has been a noticable shift in demand atleast for an
instant.
Can qsort do this and what is bubble sorting?
Bill
> Can qsort do this and what is bubble sorting?
Its not a sorting problem. You have a set of x-y coordinates and you
want to draw a graph of them, so work out the algo you need for that.
Yes! And please post it. I need a good laugh. Also include a link to
your client's web site : it will be interesting to see how your data
mining genius combined with your "from scratch rdbms" improves their
turnover in the coming months ....
6/10 + 1 bonus for snaring McIntyre.
--
"Avoid hyperbole at all costs, its the most destructive argument on
the planet" - Mark McIntyre in comp.lang.c
> Its not a sorting problem. You have a set of x-y coordinates and you want
> to draw a graph of them, so work out the algo you need for that.
OK. Hum well I wanted a function that would take numbers for quantities
for the above example,
int quant[]={3000,4500,45000};
And print out from top to bottom an ordered line in this respect. It kind of
looks like a spreadsheet.
45000
4500
3000
Bill
There are multiple tasks required. The second column data needs to be
sorted. The first column may need to be sorted (the example shown was
sorted, both on input and output, but the requirement wasn't made
explicit). And yes, there is some logic to place the "x" in the proper
column.
>> Can qsort do this and what is bubble sorting?
Yes, qsort can be used to sort column 2 and column 1, if needed. I
would place both items into a struct for sorting.
--
Thad
> Can someone tell me what kind of sort routine I would need to
> take data
> such as this and sort it this way?
>
> 23 45000
> 22 3000
> 20 4500
>
> The first column is the security price and the second the volume.
> It's to be sorted this way:
>
> 3000 4500 45000
>
> 23 x
> 22 x
> 20 x
You have two possible keys: price and volume (P and V). Since you
don't have any duplicates in your sample data, we only need one of
those keys to sort on. We can do this in four ways:
P ascending : (20, 4500), (22, 3000), (23, 45000)
P descending: (23, 45000), (22, 3000), (20, 4500)
V ascending : (22, 3000), (20, 4500), (23, 45000)
V descending: (23, 45000), (20, 4500), (22, 3000)
Of these, the one that most conveniently fits your example is P
descending. Sorting it this way enables you to display the data
without needing an intermediate array or a random-access print head.
> This is a type of supply/demand data format. In this little bit of
> data it can be seen that there has been a noticable shift in demand
> atleast for an instant.
No, it can't. An instant is a duration, but your data doesn't
incorporate durations or event times.
> Can qsort do this and what is bubble sorting?
If you have an array and a comparison function for the proper type,
and if you know how many elements the array has and how big one
element is, you can use qsort to sort that array. Bubble sorting is a
way of slowing your program down.
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
"Usenet is a strange place" - dmr 29 July 1999
Sig line vacant - apply within
/* BEGIN new.c */
#include <stdio.h>
#include <stdlib.h>
#define NMEMB(A) (sizeof(A) / sizeof*(A))
int compar(const void *A, const void *B);
int main(void)
{
unsigned quant[] = {3000, 4500, 45000};
unsigned index;
qsort(quant, NMEMB(quant), sizeof *quant, compar);
for (index = 0; index != NMEMB(quant); ++index) {
printf("%u\n", quant[index]);
}
return 0;
}
int compar(const void *A, const void *B)
{
const unsigned *p1 = A;
const unsigned *p2 = B;
return *p1 > *p2 ? -1 : *p1 != *p2;
}
/* END new.c */
--
pete
> An instant is a duration, [...].
This may be a British/American thing but one of our main dictionaries says
an instant is an infinitesimal space of time. Calculus says there is
nothing smaller than that, so an instant is a point in time.
> "Richard Heathfield" wrote:
>
>> An instant is a duration, [...].
>
> This may be a British/American thing but one of our main
> dictionaries says
> an instant is an infinitesimal space of time.
Fine, so it's a very, very small duration. Point being, there is no
mention of time in the original data - just volume and price.
> Calculus says there
> is nothing smaller than that, so an instant is a point in time.
So? There is still no mention of time in the original data, and
therefore the data don't show any changes over time, infinitesimal or
otherwise.
> In <7jlo2sF...@mid.individual.net>, osmium wrote:
>
>> "Richard Heathfield" wrote:
>>
>>> An instant is a duration, [...].
>>
>> This may be a British/American thing but one of our main
>> dictionaries says
>> an instant is an infinitesimal space of time.
>
> Fine, so it's a very, very small duration. Point being, there is no
> mention of time in the original data - just volume and price.
>
>> Calculus says there
>> is nothing smaller than that, so an instant is a point in time.
>
> So? There is still no mention of time in the original data, and
> therefore the data don't show any changes over time, infinitesimal or
> otherwise.
Bill : +1
I didn't see this thread coming ....
Store the data in a database and put an index on it.
Historical data has value in projections, and once you have 5 million
items ordered, adding 100,000 new items will not take a lot of energy
to order in amongst the rest because it will already be kept in order
and only the additions will have to be added to the leaves.
Your entire financial project screams for a database.
<snip>
> Your entire financial project screams for a database.
Hence his desire to write one, no doubt.
This kind of gives me flashbacks freshman level Calculus at UW. The
Professor started to do the proof to Rolle's Theorem. Right before he
started he said "This proof is more exciting than an episode of
Beverly Hills 90210."
My desire is now more of an interest in the alorgirthm.
Bill
SQueeL like a piggy...