找回密码
 立即注册
查看: 1267|回复: 11

求助,一个简单的数组先进先出C程序!!!

[复制链接]
  • 打卡等级:初来乍到
  • 打卡总天数:8
  • 最近打卡:2025-01-17 13:57:41

19

主题

51

回帖

491

积分

中级会员

积分
491
发表于 2023-2-9 20:28:16 | 显示全部楼层 |阅读模式
求助,一个简单的数组先进先出C程序!!!
回复

使用道具 举报 送花

  • 打卡等级:偶尔看看III
  • 打卡总天数:57
  • 最近打卡:2025-05-04 08:52:05

718

主题

1万

回帖

1万

积分

管理员

积分
15662
发表于 2023-2-9 20:42:45 | 显示全部楼层

求助,一个简单的数组先进先出C程序!!!
===我不知道梁工的串口程序有没有这段程序,发个链接你看下,
===不行请梁工再亲自写段程序给您
1.png
【新提醒】求STC8H/STC8G系列 4个串口同时通信的演示程序,Modbus 演示程序 - 串行口,DMA支持的4组串口 国芯论坛-STC全球32位8051爱好者互助交流社区 - STC全球32位8051爱好者互助交流社区 (stcaimcu.com)
2.png
不知用到先进先出没有
  • 打卡等级:以坛为家II
  • 打卡总天数:437
  • 最近打卡:2025-05-04 09:25:44
已绑定手机

229

主题

328

回帖

1483

积分

金牌会员

积分
1483
发表于 2023-2-10 00:12:30 | 显示全部楼层

  • 打卡等级:以坛为家II
  • 打卡总天数:524
  • 最近打卡:2025-05-04 02:13:29

10

主题

1161

回帖

5133

积分

论坛元老

积分
5133
发表于 2023-2-10 08:25:56 | 显示全部楼层

  1. #include <stdio.h>
  2. # define SIZE 100
  3. void enqueue();
  4. void dequeue();
  5. void show();
  6. int inp_arr[SIZE];
  7. int Rear = - 1;
  8. int Front = - 1;
  9. main()
  10. {
  11.     int ch;
  12.     while (1)
  13.     {
  14.         printf("1.Enqueue Operation\n");
  15.         printf("2.Dequeue Operation\n");
  16.         printf("3.Display the Queue\n");
  17.         printf("4.Exit\n");
  18.         printf("Enter your choice of operations : ");
  19.         scanf("%d", &ch);
  20.         switch (ch)
  21.         {
  22.             case 1:
  23.             enqueue();
  24.             break;
  25.             case 2:
  26.             dequeue();
  27.             break;
  28.             case 3:
  29.             show();
  30.             break;
  31.             case 4:
  32.             exit(0);
  33.             default:
  34.             printf("Incorrect choice \n");
  35.         }
  36.     }
  37. }
  38. void enqueue()
  39. {
  40.     int insert_item;
  41.     if (Rear == SIZE - 1)
  42.        printf("Overflow \n");
  43.     else
  44.     {
  45.         if (Front == - 1)
  46.       
  47.         Front = 0;
  48.         printf("Element to be inserted in the Queue\n : ");
  49.         scanf("%d", &insert_item);
  50.         Rear = Rear + 1;
  51.         inp_arr[Rear] = insert_item;
  52.     }
  53. }
  54. void dequeue()
  55. {
  56.     if (Front == - 1 || Front > Rear)
  57.     {
  58.         printf("Underflow \n");
  59.         return ;
  60.     }
  61.     else
  62.     {
  63.         printf("Element deleted from the Queue: %d\n", inp_arr[Front]);
  64.         Front = Front + 1;
  65.     }
  66. }
  67. void show()
  68. {
  69.    
  70.     if (Front == - 1)
  71.         printf("Empty Queue \n");
  72.     else
  73.     {
  74.         printf("Queue: \n");
  75.         for (int i = Front; i <= Rear; i++)
  76.             printf("%d ", inp_arr[i]);
  77.         printf("\n");
  78.     }
  79. }
复制代码


输出。
  1. 1.Enqueue Operation
  2. 2.Dequeue Operation
  3. 3.Display the Queue
  4. 4.Exit
  5. Enter your choice of operations : 1
  6. Element to be inserted in the Queue: 10
  7. 1.Enqueue Operation
  8. 2.Dequeue Operation
  9. 3.Display the Queue
  10. 4.Exit
  11. Enter your choice of operations : 1
  12. Element to be inserted in the Queue: 20
  13. 1.Enqueue Operation
  14. 2.Dequeue Operation
  15. 3.Display the Queue
  16. 4.Exit
  17. Enter your choice of operations : 3
  18. Queue:
  19. 10 20
  20. 1.Enqueue Operation
  21. 2.Dequeue Operation
  22. 3.Display the Queue
  23. 4.Exit
  24. Enter your choice of operations : 2
  25. Element deleted from the Queue: 10
  26. 1.Enqueue Operation
  27. 2.Dequeue Operation
  28. 3.Display the Queue
  29. 4.Exit
  30. Enter your choice of operations: 3
  31. Queue:
  32. 20
复制代码

点评

打错个字,是芯片的空间不够,完整的代码超出太多,只能用简单的程序,先谢谢了  发表于 2023-2-12 14:14
芯片的空间足够,完整的代码超出太多,只能用简单的程序,先谢谢了  发表于 2023-2-12 14:13
  • 打卡等级:偶尔看看III
  • 打卡总天数:52
  • 最近打卡:2025-05-03 23:41:15

73

主题

5884

回帖

1万

积分

超级版主

积分
12087
发表于 2023-2-10 11:25:13 | 显示全部楼层
两个变量做指示,write用于写(入),read用于读(出)。read追着write跑即可,相等则无新数据。

点评

谢谢  发表于 2023-2-12 14:12
回复 支持 1 反对 0

使用道具 举报 送花

  • 打卡等级:偶尔看看III
  • 打卡总天数:38
  • 最近打卡:2025-04-30 14:38:57

25

主题

977

回帖

3599

积分

超级版主

积分
3599
发表于 2023-2-10 17:16:31 | 显示全部楼层


STC-ISP下载软件里面的串口范例程序中
缓冲区就是最简单的先进先出的应用范例(FIFO队列环)
1.png
  • 打卡等级:初来乍到
  • 打卡总天数:8
  • 最近打卡:2025-01-17 13:57:41

19

主题

51

回帖

491

积分

中级会员

积分
491
发表于 2023-2-12 14:20:06 | 显示全部楼层
zh*** 发表于 2023-2-10 17:16
STC-ISP下载软件里面的串口范例程序中
缓冲区就是最简单的先进先出的应用范例(FIFO队列环)

谢谢提示
  • 打卡等级:偶尔看看III
  • 打卡总天数:57
  • 最近打卡:2025-05-04 08:52:05

718

主题

1万

回帖

1万

积分

管理员

积分
15662
发表于 2023-2-12 15:08:38 | 显示全部楼层
本以为是最简单的演示程序,结果还有最简单的:最简单的先进先出的应用范例(FIFO队列环)
  • 打卡等级:初来乍到
  • 打卡总天数:8
  • 最近打卡:2025-01-17 13:57:41

19

主题

51

回帖

491

积分

中级会员

积分
491
发表于 2023-2-12 23:27:07 | 显示全部楼层
神*** 发表于 2023-2-12 15:08
本以为是最简单的演示程序,结果还有最简单的:最简单的先进先出的应用范例(FIFO队列环) ...

经过测试,软件例程里串口那个确实是最简单的,几行代码就完成了需要的先进先出程序。
移植到我的工程里,运行了一下,输入端的几路脉冲信号都能按时间顺序放进数组,然后通过串口发送到上位机。
感谢官方支持,感谢热心网友支持!!!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|小黑屋|深圳国芯人工智能有限公司 ( 粤ICP备2022108929号-2 )

GMT+8, 2025-5-4 17:43 , Processed in 0.123116 second(s), 111 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表