Log In
Or create an account ->
Imperial Library
Home
About
News
Upload
Forum
Help
Login/SignUp
Index
Think Like a Programmer
Acknowledgments
Introduction
About This Book
Prerequisites
Chosen Topics
Programming Style
Exercises
Why C++?
1. Strategies for Problem Solving
Classic Puzzles
The Fox, the Goose, and the Corn
Lessons Learned
Sliding Tile Puzzles
Lessons Learned
Sudoku
Lessons Learned
The Quarrasi Lock
Lessons Learned
General Problem-Solving Techniques
Always Have a Plan
Restate the Problem
Divide the Problem
Start with What You Know
Reduce the Problem
Look for Analogies
Experiment
Don’t Get Frustrated
Exercises
2. Pure Puzzles
Review of C++ Used in This Chapter
Output Patterns
Input Processing
Breaking Down the Problem
Putting the Pieces Together
Tracking State
Conclusion
Exercises
3. Solving Problems with Arrays
Review of Array Fundamentals
Store
Copy
Retrieval and Search
Searching for a Specific Value
Criterion-Based Search
Sort
Fast-and-Easy Sorting with qsort
Easy-to-Modify Sorting with Insertion Sort
Compute Statistics
Solving Problems with Arrays
Refactoring
Arrays of Fixed Data
Non-scalar Arrays
Multidimensional Arrays
Deciding When to Use Arrays
Exercises
4. Solving Problems with Pointers and Dynamic Memory
Review of Pointer Fundamentals
Benefits of Pointers
Runtime-Sized Data Structures
Resizable Data Structures
Memory Sharing
When to Use Pointers
Memory Matters
The Stack and the Heap
Memory Size
Lifetime
Solving Pointer Problems
Variable-Length Strings
Checking for Special Cases
Copying Dynamically Allocated Strings
Linked Lists
Building a List of Nodes
Adding Nodes to a List
List Traversal
Conclusion and Next Steps
Exercises
5. Solving Problems with Classes
Review of Class Fundamentals
Goals of Class Use
Encapsulation
Code Reuse
Dividing the Problem
Information Hiding
Readability
Expressiveness
Building a Simple Class
The Basic Class Framework
Support Methods
Classes with Dynamic Data
Adding a Node
Rearranging the List
Destructor
Deep Copy
The Big Picture for Classes with Dynamic Memory
Mistakes to Avoid
The Fake Class
Single-Taskers
Exercises
6. Solving Problems with Recursion
Review of Recursion Fundamentals
Head and Tail Recursion
Approach 1
Approach 2
Approach 1
Approach 2
The Big Recursive Idea
Common Mistakes
Too Many Parameters
Global Variables
Applying Recursion to Dynamic Data Structures
Recursion and Linked Lists
Recursion and Binary Trees
Wrapper Functions
When to Choose Recursion
Arguments Against Recursion
Exercises
7. Solving Problems with Code Reuse
Good Reuse and Bad Reuse
Review of Component Fundamentals
Code Block
Algorithms
Patterns
Abstract Data Types
Libraries
Building Component Knowledge
Exploratory Learning
Putting Learning into Practice
Analysis of First Student Solution
As-Needed Learning
When to Search for a Component
Finding a Component
Applying the Component
Analysis of Efficient Traversal Solution
Choosing a Component Type
Component Choice in Action
Comparing the Results
Exercises
8. Thinking Like a Programmer
Creating Your Own Master Plan
Playing to Your Strengths and Weaknesses
Planning Against Coding Weaknesses
Planning Against Design Weaknesses
Planning for Your Strengths
Putting the Master Plan Together
Tackling Any Problem
Finding a Way to Cheat
Required Operations for Cheating at Hangman
Initial Design
Initial Coding
Analysis of Initial Results
The Art of Problem Solving
Learning New Programming Skills
New Languages
Take the Time to Learn
Start with What You Know
Investigate What’s Different
Study Well-Written Code
New Skills for a Language You Already Know
New Libraries
Take a Class
Conclusion
Exercises
Index
About the Author
Colophon
A. Updates
Copyright
← Prev
Back
Next →
← Prev
Back
Next →