sorting routine

B

Bill Cunningham

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

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
 
B

Bill Cunningham

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
 
T

Thad Smith

Mark said:
That's not sorting, thats creating a graph from the data.

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.

Yes, qsort can be used to sort column 2 and column 1, if needed. I
would place both items into a struct for sorting.
 
O

osmium

Richard Heathfield said:
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.
 
U

user923005

    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

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?

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.
 
C

chad

Richard Heathfield said:
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.

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."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top