算法-----队列

  1. packagecom.eshore.sweetop.dataframe;
  2. publicclassQuene{
  3. privateinthead=-1;
  4. privateinttail=0;
  5. privateint[]q;
  6. publicQuene(){
  7. q=newint[100];
  8. }
  9. publicQuene(intn){
  10. q=newint[n];
  11. }
  12. publicvoiden(intx){
  13. if(head==-1){
  14. head=0;
  15. }
  16. q[tail]=x;
  17. if(tail==q.length-1){
  18. tail=1;
  19. }else{
  20. tail=tail+1;
  21. }
  22. }
  23. publicintde(){
  24. intx=q[head];
  25. if(head==q.length-1){
  26. head=0;
  27. }else{
  28. head=head+1;
  29. }
  30. returnx;
  31. }
  32. publicstaticvoidmain(String[]args){
  33. Queneq=newQuene();
  34. q.en(4);
  35. q.en(3);
  36. System.out.println(q.de());
  37. System.out.println(q.de());
  38. }
  39. }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值