我有这些方法:
void loadQueue(nodePtr *start, nodePtr *end)
{
CreateQueue(&start, &end);
int c;
FILE* file = fopen("C:\\Users\\User\\Desktop\\Queue.txt", "r");
int numbers[50];
int i = 0;
while ((c = fgetc(file)) != EOF)
{
numbers[i] = atoi(&c);
i++;
}
for (int j = 0; j < i ;j++)
{
Enqueue(j, &start, &end);
}
};
现在我想使用此方法将它们放入队列中:
nodePtr CreateNode(int num) {
nodePtr p = (nodePtr)malloc(sizeof(node)); // ALLOCATE MEMORY TO ONE NODE AND SET P TO POINT TO IT
if (p != NULL) // REMEMBER always check if memory was allocated otherwise the behaviousog program is undefined :)
{
p->item = num;
p->next = NULL;
}
return p;
}
并在此方法中使用create节点:
bool Enqueue(int item, nodePtr *start, nodePtr *end) {
nodePtr newitem = CreateNode(item);
if (newitem != NULL)
{
if (isEmptyQueue(*start))
{
*start = newitem;
}
else
{
(*end)->next = newitem;
}
*end = newitem;
return true;
}
else
{
return false;
}
};
有人能告诉我如何存储我在enqueue中读取的传递的数据(数字),正如我在loadQueue方法中所做的那样。
答案 0 :(得分:0)
答案是:
void loadQueue(nodePtr *start, nodePtr *end)
{
CreateQueue(start, end);
int c;
FILE* file = fopen("C:\\Users\\User\\Desktop\\Queue.txt", "r");
int numbers[50];
int i = 0;
while ((c = fgetc(file)) != EOF)
{
numbers[i] = atoi(&c);
i++;
}
for (int j = 0; j < i ;j++)
{
Enqueue(numbers[j], start, end);
}
};
感谢BLUEPIXY