Upload
pinglun-liao
View
104
Download
0
Embed Size (px)
Citation preview
How To Program
Ping-Lun Liao
Outline
程式語言 「組成元素有什麼?」 「為什麼要有這些元素?」
如何去解程式問題的步驟 ( 如程式作業 ) 分析:問題的困難點、關鍵在那 設計:要用什麼 Data Structure 、 Algorithm 實作 Debug Source Code Version Control
實例講解
Tool and Language
Tool: Eclipse Language: Java
程式語言
0x0008
Data
Data Type (Why)– Integer– Float-point– String– Literal
• 1234• 13.333• 'a', "string"
Array– Homogeneous
0x0016
0x0024
0x0032
0x00080x00080x0008
0x00160x0016
0x0024
0x0004
0x0008
0x0012
0x0016
0x00040x00040x0004
0x00080x0008
0x0012
‘C’
‘H’
‘A’
‘R’
Control Structures
– Decision• if
• switch
– Loop• for
• while / do … while
– Jump• Goto
– Function
if
truefalse
比較兩數大小
truefalseA > B
A 比較大B 比較大
switch
想想看 switch 要怎麼畫流程圖
for / while
truefalse
Summation
truefalse i <= n
sum = sum + i
Summation
Another solution– 公式解
∑i=1
n
i=n×(n+1 )
2
do … while
怎麼畫流程圖?
Program = DS + ALG
Data Structure– Stack– Queue– …etc
Algorithm– Sort
• QuickSort• BubbleSort
– Search• BinarySearch• LinearSearch
– …etc
Stack
Queue
push
poppush
pop
Example: Prime
判斷一個數是否為質數 求出小於n ( 小於 32767) 的所有質數
Example: Diamond
* *** ***** ******* ********* *********** ************* *************** ************************************ ***************** *************** ************* *********** ********* ******* ***** *** *
Example: Diamond2
* * * * * * * * * * * * * * * * ** * * * * * * * * * * * * * * * * * *
Example: Diamond3
********* ***************** *************** ************* *********** ********* ******* ***** *** *
* *** ***** ******* ********* *********** ************* *************** ***************** *********
Example: Cross
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ** *
x
y
☆ ☆☆☆☆☆☆☆☆ ☆☆☆ ☆
Example: ?
?
Review & QA
練習題 java console 跑馬燈
Code Version Control
git github
What’s next?
Object-Oriented Programming Swing Networking Thread ...
Exercise: Longest Increasing Subsequence(LIS)
What’s LIS?– 4, 1, 3, 10, 7, 9, 8, 2, 5, 6
– (1, 3, 10) (3, 7, 9) (2, 5, 6)…
– (1, 3, 7, 9) is longest and the length is 4. Longest Increasing Subsequence
– Dynamic Programming
4, 1, 3, 10, 7, 9, 8, 2, 5, 61 1 2 3 3 4 4 2 3 4
我的連絡方式 E-mail: pinglunliao [at] gmail [dot] com LINE: Holan.Liao