Click to See Complete Forum and Search --> : sorting


Shaun
04-22-2001, 05:40 PM
Hi, can someone please tell me how to order a few numbers, using pointers.
The list has three numbers which are set deafult values.

here is part of the program Mat,Mouse and Keyboard are classes and are dynamically
created in run time...

void main(void)
{
Mat* b1 = new Mat(75.5); //deafult values
Mouse* b2 = new Mouse(55.5);
KeyBoard* b3 = new KeyBoard(125);

}
I would like to order the numbers in a new function in main

maybe it is not possible what i am tyring to do, and i might be better off
trying a different method all together in what iam trying to achive

many thanks
shaun

jonnin
04-22-2001, 10:35 PM
For 3 numbers, don't bother to sort via major algorithm. Just set max = first
value, check other 2 to see if larger, if so set max = biggest.
same for min, except now we know the max, so 2 compares. With the min and
max, you have it, use the info as you will. You can compare the pointed
to data with a dereference to use as pointers. Since these are not the same
type, you may have to code around that, maybe by making max = keyboard, min
= mouse, (int, 0,1,2 for keyboard, mouse, mat) and then create pointers for
them from that info, depends on what you have and what you want.




"Shaun" <shaun@shaudies.freeserve.co.uk> wrote:
>
>Hi, can someone please tell me how to order a few numbers, using pointers.
>The list has three numbers which are set deafult values.
>
>here is part of the program Mat,Mouse and Keyboard are classes and are dynamically
>created in run time...
>
>void main(void)
>{
> Mat* b1 = new Mat(75.5); //deafult values
> Mouse* b2 = new Mouse(55.5);
> KeyBoard* b3 = new KeyBoard(125);
>
>}
>I would like to order the numbers in a new function in main
>
>maybe it is not possible what i am tyring to do, and i might be better off
>trying a different method all together in what iam trying to achive
>
>many thanks
>shaun