- 2
- 0
- 约4.64千字
- 约 31页
- 2018-03-29 发布于广东
- 举报
刊首寄语title71
Queue C and Data Structures Baojian Hua bjhua@ustc.edu.cn Linear List Recall that a linear list has the form: The delete and insert operations may insert or delete an arbitrary element e_i If the delete is restricted at one end and insert at the other end, we get a queue Example: Queue of Char Abstract Data Types in C: Interface // in file “queue.h” #ifndef QUEUE_H #define QUEUE_H typedef struct Queue_t *Queue_t; Queue_t Queue_new (); int Queue_size (Queue_t q); int Queue_isEmpty (Queue_t q); void Queue_enQueue (Queue_t q, poly x); poly Queue_deQueue (Queue_t q); poly Queue_getHead (Queue_t q); #endif Implementation Using Extensible Array // in file “arrayQueue.c” #include “queue.h” struct Queue_t { Array_t l; }; // Recall the box strategy: Operations: “new” Queue_t Queue_new () { Queue_t q = malloc (sizeof (*q)); q-l = Array_new (); return q; } Operations: “size” int Queue_size (Queue_t q) { return Array_length (q-l); } Operations: “isEmpty” int Queue_isEmpty (Queue_t q) { return Array_isEmpty (q-l); } Operations: “enQueue” void Queue_enQueue (Queue_t q, poly x) { Array_insertLast (stk-l, x); return; } Operations: “deQueue” poly Queue_deQueue (Queue_t q) { if (Array_isEmpty (q-l)) error (“empty queue”); return Array_deleteFirst (q-l); } Operations: “deQueue” Operations: “deQueue” Analysis What’s the complexity? enQueue: O(1) deQueue: O(n) data movement Can we do better? Lazy approach better amortized performance Circular queue Lazy Approach Instead of moving data when “deQueue”, we move data only when “enQueue” reaching the tail of the queue O(n) on n operations which has O(1) amortized cost Lazy Approach What’s necessary modification? Leave this as a programming assignment Circular Queue A refinement of the lazy approach is the circular queue Circular Queue A refinement of the lazy approach is the circular queue Circular Queue A refinement of the lazy approach is the circular queue Circular Queue A refinement of the lazy ap
您可能关注的文档
最近下载
- 2021年上海市嘉定区中考英语二模试卷含解析.pdf VIP
- 2025年广东省普通高中学业水平选择性考试生物(详解版).docx VIP
- 宁德市2025-2026学年(上期)高二期末考试数学试卷(含答案).pdf
- 鄂尔多斯职业学院单招《职业适应性测试》真题(达标题)附答案详解.docx VIP
- 2025年四川中科《浅谈肥胖治疗新进展》继续教育习题答案.docx VIP
- 小学三年级数学测量单元试题.docx VIP
- 三菱变频器使用手册-FR-E540 中文版.pdf VIP
- 小升初语文练习题6年级语文.pdf VIP
- 8.1 0—3岁婴幼儿心理发展评价(课件)《0-3岁婴幼儿心理发展与教育》(华东师范大学出版社).pptx VIP
- 《测量》习题3.doc VIP
原创力文档

文档评论(0)