Cognitive radio is a promising technology that aims to provide a better utilization of the radio spectrum by giving access opportunistically to the unlicensed users or the secondary users. Spectrum sharing among secondary users is one of the main issues for developing a robust cognitive radio system. In this paper, a modified cognitive radio spectrum sharing algorithm based on the Hungarian algorithm is proposed. The algorithm divides the allocation problem into two; the first problem is when all channels satisfy the minimum quality of service for all secondary users and the second problem is when one or more of the channels fails to meet the requirements. The Hungarian algorithm is applied for the first problem to provide an optimal spectrum sharing solution between the secondary users while guaranteeing the different quality of service requested by each one. For the second problem an algorithm is proposed to find the optimal spectrum allocation for the set of channels which meet the quality of service requirements of secondary users. Simulation results are presented to show how robust is proposed algorithm to meet the required quality of service.