顺序存储队列

来源:互联网 发布:sql语句获得当前时间 编辑:程序博客网 时间:2024/05/16 18:37
  1. typedef int DATATYPE
  2. #define MAXSIZE 100
  3. int head,rear;
  4. int count=0; /*队列元素数目*/
  5. DATATYPE queue[MAXSIZE];
  6. head=0;
  7. rear=-1;
  8. /*入队*/
  9. int inqueue(DATATYPE element)
  10. {
  11. if(count >= MAXSIZE)
  12. return 0;
  13. else
  14. {
  15. queue[++rear]=element;
  16. count++;
  17. return 1;
  18. }
  19. }
  20. /*出队*/
  21. int outqueue()
  22. {
  23. if(!count)
  24. return 0;
  25. else
  26. {
  27. head++
  28. count--;
  29. return 1;
  30. }
  31. }
  32. /*取队首元素*/
  33. DATATYPE get_element()
  34. {
  35. if(!count)
  36. exit(0);
  37. else
  38. return queue[head];
  39. }