• 沒有找到結果。

陣列

N/A
N/A
Protected

Academic year: 2022

Share "陣列"

Copied!
23
0
0

加載中.... (立即查看全文)

全文

(1)

盧政良 台大資訊系

陣列

1

Array

(2)

盧政良 台大資訊系

[ ]

2

(3)

盧政良 台大資訊系

3

A是這個箱子的起跑線 aka 記憶體位址

箱子有5格

語法1:創造箱子

int int int int int

0x00abc100

0x00abc104

0x00abc108

0x00abc10c

0x00abc110 觀念

觀察:陣列是一個連續空間。

memory address

16進位(HEX)表示法

int A[5]

(4)

盧政良 台大資訊系

4

創造箱子

把東⻄放到箱子裡面

從箱子裡面拿東⻄出來

純量變數沒有辦法裝超過一筆的資料

(5)

盧政良 台大資訊系

第 1 格: A[0]

5

蛤,幹嘛不從 1 開始?

https://dvblobcdnjp.azureedge.net//

Content/Upload/Popular/Images/2017-06/

e99e6b5e-ca6c-4c19-87b7- dfd63db6381a_m.jpg

你知道嗎?Python、Java、C#、JS等等語言,其陣列 的第一格都是從零開始編號,但是很多人不知所以然。

(6)

盧政良 台大資訊系

6

A[ 0]

A[ 1]

A[ 2]

A[ 3]

A[ 4]

要往後跳2格

語法2: 存取

int int int int int

存取陣列時,中括弧內的數字 代表的是偏移量!!!

offset

(7)

盧政良 台大資訊系

Array feat. for loop

7

(8)

盧政良 台大資訊系

範例五連發

創造一個陣列並填入 n 個隨機整數。

‣ 輸出該陣列的資料於螢幕上。

找出極值與其編號。

‣ 計算該組資料的總和、平均值、標準 差。

8

#include <cmath>

pow(x, y) sqrt(x)

(9)

盧政良 台大資訊系

排序

9

http://visualgo.net/sorting

(10)

盧政良 台大資訊系

10

交換

swap

氣泡排序法

(11)

盧政良 台大資訊系

https://lh4.googleusercontent.com/proxy/FjYaCPgU5DXGOnOe6uF7rs-9naPPzFDCb1ttsIKW32osIfRCI_6ArZZ4N7z1GNEaE5OkvJZMAi4- dtF9dYodCGgaaPZIeKmb9dz6bFhPxSeZyffON9XYt-Y=s0-d

ðWinner winner, chicken dinner.ó

11

(12)

盧政良 台大資訊系

12

如何洗 牌

https://www.imdb.com/title/tt0478087/videoplayer/vi313655577

(13)

盧政良 台大資訊系

13

這是重複排列啊!

人生就是這個but...

https://blog.codinghorror.com/the-danger-of-naivete/

(14)

盧政良 台大資訊系

14

不重複排列

(15)

盧政良 台大資訊系

15

模擬骰子 練習

‣ 擲一顆公正的骰子六千次。

‣ 紀錄每一面出現的次數。

‣ 輸出該骰子每面的機率。

(16)

盧政良 台大資訊系

16

Code smart, smart code!

(17)

盧政良 台大資訊系

‒ 風清揚。笑傲江湖

ð若你根本無招,

如何被破招?ó

17

http://pic.pimg.tw/bclwithlove/4bbce4ec6eb76.jpg

(18)

盧政良 台大資訊系

18

凱薩加密

https://zh.wikipedia.org/zh-tw/凱撒密碼

案例討論

(19)

盧政良 台大資訊系

19

(20)

盧政良 台大資訊系

20

二維陣列

(21)

盧政良 台大資訊系

21

https://g.co/kgs/ucGyJU

練習

https://www.csie.ntu.edu.tw/~d00922011/cpp/ooxx.cpp

(22)

盧政良 台大資訊系

高中生程式解題系統

22

(23)

盧政良 台大資訊系

LeetCode

23

https://leetcode.com/problemset/all/

參考文獻

相關文件

Larsen

 lower triangular matrix: 下三角矩陣.  upper triangular matrix:

„ FPGA –現場可規劃邏輯陣列 (field- programmable

„ FPGA –現場可規劃邏輯陣列 (field- programmable

„ FPGA –現場可規劃邏輯陣列 (field- programmable

„ FPGA –現場可規劃邏輯陣列 (field- programmable

„ FPGA –現場可規劃邏輯陣列 (field- programmable

„ FPGA –現場可規劃邏輯陣列 (field- programmable