80 likes | 93 Views
Some intro stuff. Speed Programming. Some Programming Hints. Write the Comments first Document your variables Use Symbolic Constants Don’t use enumerated types unless you really need to. Use subroutines as much as you can. If you are using debugging statements, make them meaningful.
E N D
Some intro stuff Speed Programming
Some Programming Hints • Write the Comments first • Document your variables • Use Symbolic Constants • Don’t use enumerated types unless you really need to. • Use subroutines as much as you can. • If you are using debugging statements, make them meaningful. • Use the STL (strings, stacks, queues, etc..)
Some general testing hints • Test the given input. • Test incorrect input (if necessary) • Test boundary conditions. • Check for “off-by-one” errors. • Test cases where you can compute the answer. • Test large cases (even if you do not know the answer; just in case). • Get to know your debugger.
Some more general testing hints • Display data structures • Test all invariants. • Inspect your code. • Make your debugging print statements meaningful • If you use arrays, make them larger than necessary • Make sure your bugs are really bugs
Character stuff • Check non-printable characters. • Letters and digits are sequential, all kinds of tricks. • Iteration • Conversion-upper to lower or viceversa • Conversion: chracter to rank • Newline and carriage return are a pain when converting between systems. • Unicode is another story.
String representations • End marker • Array plus length • Linked list • Others? • Big effect on operations.
Sorting Applications: • Uniqueness testing • Deleting duplicates • Event prioritizing • Median selection • Frequency coounting • Set operations • Finding target pairs • Efficient searching
Sorting algorithms • Insertion • Selection • Bubble or exchange sort • Shell-sort (insertion with diminishing increment) • Heapsort • Quicksort • mergesort