佇列(Queue)
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
一、定義
佇列(Queue)是一種 先進先出(FIFO, First-In First-Out) 的資料結構。
- 想像成排隊買票,先排的人先被服務。
- 常見於工作排程、緩衝區、印表機任務等應用。
二、基本操作
操作名稱 |
說明 |
enqueue |
將元素加入佇列尾端 |
dequeue |
移除佇列前端的元素 |
front |
查看佇列前端的元素但不移除 |
rear |
佇列最尾端元素 |
isEmpty |
檢查佇列是否為空 |
四、C 語言實作(使用陣列)
五、應用實例
- 工作排程(如列印佇列)
- 資源共享排隊(CPU、I/O 排程)
- 緩衝區(Buffer)實作
- BFS(廣度優先搜尋)
- 網路封包處理