In this paper, we develop a spectrum allocation algorithm for hierarchical cognitive ad hoc networks based on the secondary user (SU) priority. The algorithm assures that the SUs with higher priority can get more spectrum bandwidths, and thus the revenue of the whole spectrum band can be maximized. The proposed algorithm is a twostage spectrum allocation scheme, in which the licensed spectrum allocation between the primary users (PUs) and SUs acting as CH (CH-SU) is implemented in the first stage, and in the second stage, the spectrum purchased from spectrum owner is traded between the CH-SUs and cluster member (CM)-SUs. Performance analysis shows that the convergence speed of the proposed algorithm can be improved by adjusting the value of learning factors. Meanwhile, it allocates different size of spectrum bandwidth for SUs according to the different priority levels, which reflect the rationality and difference in spectrum allocation. Also, the simulation results reveals if the number of priority level of CM-SUs is less than 4, our algorithm has the lower time overhead than other spectrum allocation algorithm without taking the SU's priority level into consideration.