增加顺序语法的STL priority_queue

时间:2018-03-19 04:27:59

标签: c++ stl priority-queue

我检查了要按递增顺序获取STL priority_queue,我们需要以这种方式声明它:

import matplotlib.pyplot as plt
import matplotlib.text

fig, ax = plt.subplots()

ax.plot([5,1], label="Label 1")
ax.plot([3,0], label="Label 2")

legend = ax.legend(loc="upper right")

# Create offset from lower right corner of legend box,
# (1.0,0) is the coordinates of the offset point in the legend coordinate system
offset = matplotlib.text.OffsetFrom(legend, (1.0, 0.0))
# Create annotation. Top right corner located -20 pixels below the offset point 
# (lower right corner of legend).
ax.annotate("info_string", xy=(0,0),size=14,
            xycoords='figure fraction', xytext=(0,-20), textcoords=offset, 
            horizontalalignment='right', verticalalignment='top')
# Draw the canvas for offset to take effect
fig.canvas.draw()

fig.savefig('plot1.png')
fig.savefig('plot1.pdf')

plt.show()

有人可以解释一下这种语法吗?这个priority_queue<int, vector<int>, greater<int>> q; (为什么是矢量?)和vector<int>代表什么?

1 个答案:

答案 0 :(得分:1)

vector<int>是底层容器。 priority_queue<>是适配器。

http://en.cppreference.com/w/cpp/container/priority_queue