C#, Lesson 6 of "Xiaobai Learning Program": Queue (Queue) Second, the application of queues, writing "Real-time Calling System"

How is the "calling system" that is common in hospitals implemented?

1 text format


/// <summary>
/// The following defines a new queue to demonstrate "Real-time Calling System"
/// </summary>
Queue<Classmate> q2 = new Queue<Classmate>();

/// <summary>
/// Lesson 6 of "Xiaobai Learning Program": Application of Queue ——— "Real-time Calling System"
/// </summary>
/// <param name=" sender"></param>
/// <param name="e"></param>
private void button6_Click(object sender, EventArgs e)
{     // #1 queue     int n = 8;     for (int i = 0; i < n; i++)     {         if (mates[i].Gender == "Male")         {             q2.Enqueue(mates[i]);         }     }








    // #2 Start "Real-time Calling System"
    // Call a person every 2 seconds (2000 milliseconds)
    timer1.Interval = 2000;
    // Give true to start; give false to stop!
    timer1. Enabled = true;
}

/// <summary>
/// Operation of "Real-time Calling System"
/// This function will only be executed when it is "started".
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void timer1_Tick(object sender, EventArgs e)
{     // When there are still members in the queue;     if (q2.Count > 0)     {         // Display the first member information         Classmate m = q2.Dequeue();         webBrowser1.DocumentText = m.Id + " " + m.Name + ": " + m.Gender;     }     else     {         webBrowser1.DocumentText = "Nobody!";     } }












 

2 code format


/// <summary>
/// 下面定义一个新的队列,用于演示《实时叫号系统》
/// </summary>
Queue<Classmate> q2 = new Queue<Classmate>();

/// <summary>
/// 《小白学程序》第六课:队列(Queue)的应用————《实时叫号系统》
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button6_Click(object sender, EventArgs e)
{
    // #1 排队
    int n = 8;
    for (int i = 0; i < n; i++)
    {
        if (mates[i].Gender == "男")
        {
            q2.Enqueue(mates[i]);
        }
    }

    // #2 启动《实时叫号系统》
    // 每间隔2秒(2000毫秒)钟叫一个人
    timer1.Interval = 2000;
    // 给 true 是启动;给 false 就是停止!
    timer1.Enabled = true;
}

/// <summary>
/// 《实时叫号系统》的运行
/// 本函数只有被“启动”才执行。
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void timer1_Tick(object sender, EventArgs e)
{
    // 当队列里面还有成员的时候;
    if (q2.Count > 0)
    {
        // 显示第一位成员信息
        Classmate m = q2.Dequeue();
        webBrowser1.DocumentText = m.Id + " " + m.Name + ": " + m.Gender;
    }
    else
    {
        webBrowser1.DocumentText = "没人啦!";
    }
}

You are very lucky to read the first real programming tutorial.

Guess you like

Origin blog.csdn.net/beijinghorn/article/details/132438860