当前位置:   article > 正文

队列的入队、出队操作实现_c++普通队列能同时进出吗

c++普通队列能同时进出吗

C++代码如下:

  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <conio.h>
  5. using namespace std;
  6. typedef struct student
  7. {
  8. int data;
  9. struct student *next;
  10. }node;
  11. typedef struct linkqueue //队列有两个节点,头节点和尾节点
  12. {
  13. node *first,*rear;
  14. }queue;
  15. queue *insert(queue *HQ,int x) //入队
  16. {
  17. node *s;
  18. s=(node *)malloc(sizeof(node));
  19. s->data=x;
  20. s->next=NULL;
  21. if (HQ->rear==NULL)
  22. {
  23. HQ->first=s;
  24. HQ->rear=s;
  25. }
  26. else
  27. {
  28. HQ->rear->next=s;
  29. HQ->rear=s;
  30. }
  31. return HQ;
  32. }
  33. queue *del(queue *HQ) //出队
  34. {
  35. node *p;
  36. int x;
  37. if (HQ->first==NULL)
  38. {
  39. cout<<"溢出";
  40. }
  41. else
  42. {
  43. x=HQ->first->data;
  44. p=HQ->first;
  45. if (HQ->first==HQ->rear)
  46. {
  47. HQ->first=NULL;
  48. HQ->rear=NULL;
  49. }
  50. else
  51. {
  52. HQ->first=HQ->first->next;
  53. free(p);
  54. }
  55. return HQ;
  56. }
  57. }


声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/706997
推荐阅读
相关标签
  

闽ICP备14008679号