阿摩線上測驗 登入

申論題資訊

試卷:106年 - 106 國立中山大學_碩士班招生考試_電機系(丙組):離散數學#109065
科目:中山◆電機◆離散數學
年份:106年
排序:5

申論題內容

6.(10%) Write an algorithm queue partitioning(g. k) to reorder all data elements in a queue q. Assume that the queue q has n integer elements initially. Given an integer k > 1, the reordering will form k ordered partitions of these integers. The resulting queue should be in the order of partition 0, partition 1, and partition k-1. The62cd2fba89a98.jpgpartition of these integer elements contains all integer elements e in the original queue such that e mod k= i. (In this algorithm, you can utilize an empty queue q2 as a local variable.) You can use a function length(q) to get the length of the queue q.
For illustration, Figure 3 shows an example with an initial queue state, k = 3, ordered partitions, and a final queue state.

62cd2fec1ff54.jpg