数据结构顺序队出队操作

东野# 2017-09-30 11:07:23
数据结构顺序队元素X出队操作
qu.front=(qu.front+1)%MaxSize;
x=qu.data[qu.front];

此时x所代指的是front的元素的值还是front+1的值?

我个人感觉是front+1,但是出队应该是front的值,第一句之后front不应该是往后移了一位吗,所以我感觉应该是front+1,不知道为什么错
...全文
673 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
ba_wang_mao 2018-02-01
  • 打赏
  • 举报
回复
struct tagGPS_QUEUE GPS_QUEUE; void GPS_QUEUE_Init(void) { GPS_QUEUE.rear = 0; GPS_QUEUE.front = 0; } BOOL GPS_QUEUE_EMPTY(void) { if (GPS_QUEUE.rear == GPS_QUEUE.front) return (TRUE); return (FALSE); } BOOL GPS_QUEUE_FULL(void) { if ((GPS_QUEUE.rear+1) % GPS_QUEUE_MAX_LENGTH == GPS_QUEUE.front) return (TRUE); return (FALSE); } BOOL GPS_QUEUE_In(GPS_STRUCT GPs , uint8_t Func , uint16_t stop_time) { if (!GPS_QUEUE_FULL()) { GPS_QUEUE.rear = (GPS_QUEUE.rear + 1) % GPS_QUEUE_MAX_LENGTH; GPS_QUEUE.GPS_element[GPS_QUEUE.rear].Func = Func; GPS_QUEUE.GPS_element[GPS_QUEUE.rear].X1 = GPs.modbus_X1; GPS_QUEUE.GPS_element[GPS_QUEUE.rear].X2 = GPs.modbus_X2; GPS_QUEUE.GPS_element[GPS_QUEUE.rear].Y1 = GPs.modbus_Y1; GPS_QUEUE.GPS_element[GPS_QUEUE.rear].Y2 = GPs.modbus_Y2; GPS_QUEUE.GPS_element[GPS_QUEUE.rear].Z1 = GPs.modbus_Z1; GPS_QUEUE.GPS_element[GPS_QUEUE.rear].Z2 = GPs.modbus_Z2; GPS_QUEUE.GPS_element[GPS_QUEUE.rear].speed1 = GPs.modbus_speed1; GPS_QUEUE.GPS_element[GPS_QUEUE.rear].speed2 = GPs.modbus_speed2; GPS_QUEUE.GPS_element[GPS_QUEUE.rear].pos_status = GPs.pos_status; GPS_QUEUE.GPS_element[GPS_QUEUE.rear].year = GPs.year; GPS_QUEUE.GPS_element[GPS_QUEUE.rear].month = GPs.month; GPS_QUEUE.GPS_element[GPS_QUEUE.rear].day = GPs.day; GPS_QUEUE.GPS_element[GPS_QUEUE.rear].hour = GPs.hour; GPS_QUEUE.GPS_element[GPS_QUEUE.rear].minute = GPs.minute; GPS_QUEUE.GPS_element[GPS_QUEUE.rear].second = GPs.second; GPS_QUEUE.GPS_element[GPS_QUEUE.rear].stop_time = stop_time; return (TRUE); } return (FALSE); } BOOL GPS_QUEUE_Out(GPS_QUEUE_ELEMENT *element) { if (!GPS_QUEUE_EMPTY()) { GPS_QUEUE.front = (GPS_QUEUE.front + 1) % GPS_QUEUE_MAX_LENGTH; element->Func = GPS_QUEUE.GPS_element[GPS_QUEUE.front].Func; element->X1 = GPS_QUEUE.GPS_element[GPS_QUEUE.front].X1; element->X2 = GPS_QUEUE.GPS_element[GPS_QUEUE.front].X2; element->Y1 = GPS_QUEUE.GPS_element[GPS_QUEUE.front].Y1; element->Y2 = GPS_QUEUE.GPS_element[GPS_QUEUE.front].Y2; element->Z1 = GPS_QUEUE.GPS_element[GPS_QUEUE.front].Z1; element->Z2 = GPS_QUEUE.GPS_element[GPS_QUEUE.front].Z2; element->speed1 = GPS_QUEUE.GPS_element[GPS_QUEUE.front].speed1; element->speed2 = GPS_QUEUE.GPS_element[GPS_QUEUE.front].speed2; element->pos_status = GPS_QUEUE.GPS_element[GPS_QUEUE.front].pos_status; element->year = GPS_QUEUE.GPS_element[GPS_QUEUE.front].year; element->month = GPS_QUEUE.GPS_element[GPS_QUEUE.front].month; element->day = GPS_QUEUE.GPS_element[GPS_QUEUE.front].day; element->hour = GPS_QUEUE.GPS_element[GPS_QUEUE.front].hour; element->minute = GPS_QUEUE.GPS_element[GPS_QUEUE.front].minute; element->second = GPS_QUEUE.GPS_element[GPS_QUEUE.front].second; element->stop_time = GPS_QUEUE.GPS_element[GPS_QUEUE.front].stop_time; return (TRUE); } return (FALSE); }
Moyiii 2017-10-16
  • 打赏
  • 举报
回复
看起来的确有些问题。很少见有front的下一位指向实际的队列头的。一般是rear往后指一位。

33,009

社区成员

发帖
与我相关
我的任务
社区描述
数据结构与算法相关内容讨论专区
社区管理员
  • 数据结构与算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧