我需要实现FIFO链接列表队列,该队列可以使用当前元素进行布局,并为用户选择排队/出队/退出选项 . 如果选择了enqueue选项,请输入一个字符串并将此字符串排入队列 . 如果选择了出列,则将一个元素出列 . 同时,程序每5秒将一个元素出列一个元素,并且每10秒将一个元素(例如:a1,a2,a3,...)排入队列 . 从链接列表中排队/出列后,显示队列中的当前元素并准备好进行下一个选择 . 当入队(10秒)/出队(5秒)/退出时,UI更新/刷新 . 如果队列中没有元素或没有输入选择,则不需要更新 .

这是数据结构 .

QElement* head;
QElement* tail;

typedef struct{
  char element[20];
  QElement* next;
}QElement;

enq();
deq();

示例场景:

当前元素:N / A当前时间:17:59:12请输入选项(1.Enq; 2. Deq,3 . Exit):ß无输入元素:a1已入队 . 从17:59:12开始10秒

当前元素:a1当前时间:17:59:22请输入选项(1.Enq; 2. Deq,3.Exit):ß无输入元素:a1已出列 . 从17:59:22起5秒

当前元素:N / A当前时间:17:59:27请输入选项(1.Enq; 2. Deq,3.Exit):1请输入字符串:ABC元素:ABC已入队 .

当前元素:ABC当前时间:17:59:28请输入选项(1.Enq; 2. Deq,3.Exit):1请输入字符串:DEF元素:DEF已入队 .

当前元素:ABC-> DEF当前时间:17:59:29请输入选项(1.Enq; 2. Deq,3.Exit):元素:a2已入队 . 10秒从17:59:22元素:ABC出列了 . 从17:59:27开始55秒

当前元素:DEF-> a2当前时间:17:59:32请输入选项(1.Enq; 2. Deq,3.Exit):请输入字符串:IJK元素:IJK已入队 .

当前元素:DEF-> a2-> IJK当前时间:17:59:34请输入选项(1.Enq; 2. Deq,3.Exit):

我的代码没有完成:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <windows.h>
#include <unistd.h>

typedef struct A{
    char element[20];
    struct QElement* next;
    }QElement;

QElement* head = NULL;
QElement* tail = NULL;




int main()
{
char data[] = "a";
int i = 2;
while(i--) {

    if (Isitempty(head,tail)) {
        printf("Current Element: N/A\n");
    }
    else {
        Print();
    }
    time_t now = time(NULL);
    printf("Current time: %s",ctime(&now));
    printf("Please enter the option(1.Enq; 2. Deq, 3.Exit):\n");
    //SetTimer(NULL, 1, 100, enq(data));

    enq(data);
    enq(data);
}




return 0;
}


int Isitempty(QElement* front,QElement* end) {
if (front==NULL && end == NULL) {
    return 1;
}
return 0;
}

void enq(char data[]) {
QElement* temp = (QElement*)malloc(sizeof(QElement));

strcpy(temp->element,data);
temp->next = NULL;
if (head == NULL && tail == NULL) {
    head = temp;
    tail = temp;

    printf("Element: %s is enqueued\n", temp->element);


    return;
}
tail->next = temp;
tail = temp;

printf("Element: %s is enqueued\n", temp->element);


free(temp);
return;
}

void Print() {
QElement* temp = (QElement*) malloc(sizeof(QElement));
temp = head;

for (temp ; temp != NULL ; temp=temp->next) {
    printf("Current Element: %s",temp->element);
    //temp = temp->next;
}
}

idk为什么在Print()函数中,for循环不会结束?我认为最后temp必须为NULL . 但它不起作用 . 我真的不知道如何处理计时器和用户选择enq / deq / exit . 请有人帮帮我吗?