Data Structures and Algorithms pptx

7 464 0
Data Structures and Algorithms pptx

Đang tải... (xem toàn văn)

Thông tin tài liệu

Data Structures and Algorithms City Univ of HK / Dept of CS / Helena Wong 0. Course Introduction - 1 http://www.cs.cityu.edu.hk/~helena Data Structures and Algorithms Reference : Dr. Halena Wong – www.cs.cityu.edu.hk Lecturer : MSc. Trinh Quoc Son University of Information Technology Email : sontq@uit.edu.vn Data Structures and Algorithms City Univ of HK / Dept of CS / Helena Wong 0. Course Introduction - 2 http://www.cs.cityu.edu.hk/~helena … Shaffer Standish Gilberg Reference Books D a t a S t r u c t u r e s U s i n g C a n d C + + B y L a n g s a m , A u g e n s t e i n , T e n e n b a u m [ P r e n t i c e H a l l ] Data Structures and Algorithm Analysis in C By Mark Allen Weiss [Addison Wesley] Data Structures and Algorithms City Univ of HK / Dept of CS / Helena Wong 0. Course Introduction - 3 http://www.cs.cityu.edu.hk/~helena Programming Language and Tools • We will write programs in C language • Assignment/exercises can be use with Visual C++ Week 1,2 (at home) • Review C programming • If you have missed something, find your tutor immediately! If you consider other C programming tools: eg. Visual Studio.Net, Pelles C (http://www.smorgasbordet.com/pellesc/) - The compiler acts in the same way as Visual C++? Mostly not. Data Structures and Algorithms City Univ of HK / Dept of CS / Helena Wong 0. Course Introduction - 4 http://www.cs.cityu.edu.hk/~helena Comments (Enough but not excess!) • Describe the program at the beginning • Describe important variables and global declarations • Describe each function before the function • Explain any complex logic Indentation (use tabs) / format: if (x>y) county++; else if (x>z) {countz++; countx++;} Hard coding should be avoided: if (x >36) { x=0; y++; } GOOD const int WIDTH=36; if (x >WIDTH) { x=0; y++; } if (x>y) county++; else if (x>z) {countz++; countx++; } GOOD U s i n g n a m e d c o n s t a n t Global variables: only if necessary and appropriate int i, j; void count() { for (i=0;… … } void main() { for (i=0;… … } const int SIZE=10; int table[SIZE][SIZE]; void PrintTable() { } void main() { } OK Data Structures and Algorithms City Univ of HK / Dept of CS / Helena Wong 0. Course Introduction - 5 http://www.cs.cityu.edu.hk/~helena Program bugs are normal You should fix them! Trust yourself: Your program is based on a workable logic, right? Now, the error is probably due to careless mistakes only . With 99.9% sure these mistakes can be caught by using the debugger. Design of logic Coding Testing !! ERROR But after I have corrected the bug, the program still goes wrong. Should I undo the correction? No. Don’t undo the correction. Now there is probably another small bug that you need to fix. Don’t give up. You are approaching to success. Data Structures and Algorithms City Univ of HK / Dept of CS / Helena Wong 0. Course Introduction - 6 http://www.cs.cityu.edu.hk/~helena Any problem in fixing a program bug? • First of all: solve for all compilation warnings(these are usually hints of bugs) • A general debugging cycle: 1. Test it again with simple test cases (increase complexity gradually) 2. Select a simplest test case that your program runs incorrectly. 3. With the test case, trace the code with pencil and paper. (write down all intermediate results obtained step-by-step) 4. Run your program with debugger to trace the program (adding breakpoints / tracing line by line) Locate the statement that causes any difference compared with your pencil-and-paper tracing. 5. Fix the bug. 6. Test the program with another test case. Trust yourself on the logic: “the bug should be a careless mistake and can be fixed” – otherwise you will never start debugging. get Help (MSDN): a convenient reference for C. Data Structures and Algorithms City Univ of HK / Dept of CS / Helena Wong 0. Course Introduction - 7 http://www.cs.cityu.edu.hk/~helena • Send me emails to ask any question of this course. • Email subject should be relevant eg. “help”. • Attach any related program source code and test case. Any problem in this course? I may contact you by email. If you prefer NOT to receive my email, please inform me as soon as possible. . [ P r e n t i c e H a l l ] Data Structures and Algorithm Analysis in C By Mark Allen Weiss [Addison Wesley] Data Structures and Algorithms City Univ of. Data Structures and Algorithms City Univ of HK / Dept of CS / Helena Wong 0. Course Introduction - 1 http://www.cs.cityu.edu.hk/~helena Data Structures

Ngày đăng: 22/03/2014, 20:21

Từ khóa liên quan

Mục lục

  • Slide 1

  • Reference Books

  • Programming Language and Tools

  • Slide 4

  • Program bugs are normal -- You should fix them!

  • Any problem in fixing a program bug?

  • Any problem in this course?

Tài liệu cùng người dùng

Tài liệu liên quan