数据结构 queue java_数据结构——java Queue类

1 packagejava.util;2

3 public interface Queue extends Collection{4 /**

5 * Inserts the specified element into this queue if it is possible to do so6 * immediately without violating capacity restrictions, returning7 * {@codetrue} upon success and throwing an {@codeIllegalStateException}8 * if no space is currently available.9 *10 *@parame the element to add11 *@return{@codetrue} (as specified by {@linkCollection#add})12 *@throwsIllegalStateException if the element cannot be added at this13 * time due to capacity restrictions14 *@throwsClassCastException if the class of the specified element15 * prevents it from being added to this queue16 *@throwsNullPointerException if the specified element is null and17 * this queue does not permit null elements18 *@throwsIllegalArgumentException if some property of this element19 * prevents it from being added to this queue20 */

21 booleanadd(E e);22

23 /**

24 * Inserts the specified element into this queue if it is possible to do25 * so immediately without violating capacity restrictions.26 * When using a capacity-restricted queue, this method is generally27 * preferable to {@link#add}, which can fail to insert an element only28 * by throwing an exception.29 *30 *@parame the element to add31 *@return{@codetrue} if the element was added to this queue, else32 * {@codefalse}33 *@throwsClassCastException if the class of the specified element34 * prevents it from being added to this queue35 *@throwsNullPointerException if the specified element is null and36 * this queue does not permit null elements37 *@throwsIllegalArgumentException if some property of this element38 * prevents it from being added to this queue39 */

40 booleanoffer(E e);41

42 /**

43 * Retrieves and removes the head of this queue. This method differs44 * from {@link#poll poll} only in that it throws an exception if this45 * queue is empty.46 *47 *@returnthe head of this queue48 *@throwsNoSuchElementException if this queue is empty49 */

50 E remove();51

52 /**

53 * Retrieves and removes the head of this queue,54 * or returns {@codenull} if this queue is empty.55 *56 *@returnthe head of this queue, or {@codenull} if this queue is empty57 */

58 E poll();59

60 /**

61 * Retrieves, but does not remove, the head of this queue. This method62 * differs from {@link#peek peek} only in that it throws an exception63 * if this queue is empty.64 *65 *@returnthe head of this queue66 *@throwsNoSuchElementException if this queue is empty67 */

68 E element();69

70 /**

71 * Retrieves, but does not remove, the head of this queue,72 * or returns {@codenull} if this queue is empty.73 *74 *@returnthe head of this queue, or {@codenull} if this queue is empty75 */

76 E peek();77 }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值