当前位置:编程学习 > C#/ASP.NET >>

年度单身舞会队列

using System; 
using System.Collections; 
using System.Collections.Generic; 
using System.IO; 
using System.Linq; 
using System.Text; 
 
namespace TestOfQueueDancers 

    class Program 
    { 
        static void Main(string[] args) 
        { 
            Queue males = new Queue(); 
            Queue females = new Queue(); 
             
            FormLines(males,females); 
            StartDancing(males,females); 
 
            if (males.Count > 0 || females.Count > 0) 
            { 
                HeadOfLine(males,females); 
            } 
 
            NewDancers(males,females); 
 
            if (males.Count > 0 || females.Count > 0) 
            { 
                HeadOfLine(males,females); 
            } 
 
            NewDancers(males,females); 
            Console.WriteLine("Press Enter"); 
 
        } 
 
        static void NewDancers(Queue male, Queue female) 
        { 
            Dancer m, w; 
            m = new Dancer(); 
            w = new Dancer(); 
 
            if (male.Count > 0 && female.Count > 0) 
            { 
                m.GetName(male.Dequeue().ToString()); 
                w.GetName(female.Dequeue().ToString()); 
            } 
            else if ((male.Count > 0) && (female.Count == 0)) 
            { 
                Console.Write("Wating for female dancer."); 
            } 
            else if ((female.Count > 0) && (male.Count == 0)) 
            { 
                Console.Write("Wating for male dancer."); 
            } 
        } 
 
        public static void HeadOfLine(Queue male, Queue female) 
        { 
            Dancer w, m; 
            w = new Dancer(); 
            m = new Dancer(); 
 
            if (male.Count > 0) 
            { 
                m.GetName(male.Peek().ToString()); 
            } 
            if (female.Count > 0) 
            { 
                w.GetName(female.Peek().ToString()); 
            } 
 
            if (!string.IsNullOrEmpty(m.name) && 
                !string.IsNullOrEmpty(w.name)) 
            { 
                Console.WriteLine("Next in line are:" + m.name + "\t" + w.name); 
            } 
            else 
            { 
                if (!string.IsNullOrEmpty(m.name)) 
                { 
                    Console.WriteLine("Next in line is:" + m.name); 
                } 
                else 
                { 
                    Console.WriteLine("Next in line is:" + w.name); 
                } 
            } 
        } 
 
        public static void StartDancing(Queue male, Queue female) 
        { 
            Dancer m, w; 
            m = new Dancer(); 
        &nb

补充:软件开发 , C# ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,