请帮助如何打印带有队列的行 [英] Please Help with How to Print Lines with Queues

查看:121
本文介绍了请帮助如何打印带有队列的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助人们确定要转到哪一行以及如何打印这些行.我不确定是否应该执行功能或在main中进行操作.

I need help with making people decide which line to go to and how to print the lines. I''m not sure if I should make a function or do it in main.

//These are my structs:
// Stores node of the linked list.
struct node {
    int data;
    struct node* next;
};

// Stores queue.
struct queue {
    struct node* front;
    struct node* rear;
};

//These are my lines:
struct queue *LineA, *LineB, *LineC;
LineA = malloc(sizeof(struct queue));
LineB = malloc(sizeof(struct queue));
LineC = malloc(sizeof(struct queue));

//This is my file and the info being scanned in 
fp = fopen("input.txt", "r");
fscanf(fp, "%d", &seconds); 
fscanf(fp, "%s", names);
fscanf(fp, "%d", &num_items);



我尝试在函数中执行以下操作:



I tried doing something like this in a function:

for(i=0; i<=MAX_CUSTOMERS; i++)
{
    if (items<=10 && LineA!=NULL)
        printf ("%d ", LineA->data);
        LineA = LineA -> next;
    else if (lineB!=NULL)
        printf ("%d ", LineB->data);
        LineB = LineB -> next;
    else if (lineC!=NULL)
        printf ("%d ", LineC->data);
        LineC = LineC -> next;
}



但出现错误,因为它更多地用于struct节点,并且行位于struct队列中,但是我真的不知道如何打印队列.

输出应该说出时间,客户名称以及他们要检查的行,然后是时间,名称,他们要检查的行以及行的时间.



but got an error because it''s more for the struct node and the lines are in struct queue, but I don''t really know how to print a queue.

The output is supposed to say the time, the customer name, and what line they''re checking into, then time, name, what line they''re checking out of, and how long they were in line for.

推荐答案

我认为,与不知道如何打印队列"相比,您的问题要深得多.如何将客户插入您的队列,以及如何将其从队列中删除? (提示,队列的入队方法将是在客户结构中设置队列进入时间的好地方-该结构在哪里?同样,出队方法是退出时间和总数的好地方).如何确定队列中的元素数量,它仅具有指向第一个和最后一个元素的指针?

行和队列有什么区别?
节点结构到底是做什么用的? (数据是一个毫无意义的变量名,它根本无法帮助理解目的-好的,有意义的,精确的变量名是编写好的程序的重要组成部分.)

这段代码是如此混乱,以至于我无法理解其意图.退后一步,重新思考问题.
I think your problem goes far deeper than not knowing how to "print a queue". How do customers get inserted into your queues, and how to they get removed from it? (Hint, the enqueue method of a queue would be a good place to set the queue entry time in the customer struct - where is that struct? Likewise the dequeue method is a good place for the exit time and total). How do you determine the number of elements in the queue, it only has pointers to the first and last element?

What is the difference between a line and a queue?
What exactly is the node structure for? (data is such a meaningless variable name that it doesn''t help with understanding the purpose at all - good, meaningful, precise variable names are an important part of writing good programs).

This code is so confused, that I can''t divine its intent. Step back and rethink the problem.


这篇关于请帮助如何打印带有队列的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆