Re: Swap and Compare functions


[ Follow Ups ] [ Post Followup ] [ CS2604 Discussion WWWBoard ] [ FAQ ]

Posted by hussein on August 02, 1999 at 10:31:06:

In Reply to: Re: Swap and Compare functions posted by study break on August 02, 1999 at 10:13:58:

: : : In the project specification it says we must make functions to make comparisons and swaps. I wrote a swap function, but I used a counter to be incremented before comparisons. Is this OK?

: : personally, i dont particularly care, but if the specification says you should write a function, u should probably write a function ...

: You are eventually going to have to swap the values, how are you going to change the array around if you are just making comparisons? I think that sentence in the specifications was poorly worded... It's pointless to write a function that does the comparisions and another to do the swaps (which will need the comparisons anyway).

pointless ? poorly worded ? apparently, u missed the point altogether ... the point of writing functions is :-

1. the principle of abstraction implies that an algorithm you write should not be specific to a particular problem - hence using functions for comparisons and swaps means that the timing information could be removed without modifying the crux of the code.

2. using functions means that u dont have to duplicate the timing code for every algorithm.

3. by using functions u can separate timing from the actual algorithm - and such minimal changes are important to ensure correctness of the simulation

4. u cannot make the assumption that a comparison always leads to a swap (eg. mergesort)

5. in a o-o implementation, operators could be overloaded to perform swaps/comparisons using "functions"

---

hussein


Follow Ups:



Post a Followup

Name:
E-Mail:

Subject:

Comments:

Optional Link URL:
Link Title:
Optional Image URL:


[ Follow Ups ] [ Post Followup ] [ CS2604 Discussion WWWBoard ] [ FAQ ]