Find() public method

public Find ( string name ) : int
name string
return int
    static void Main()
    {
        StringBuilder output = new StringBuilder();
        string commandLine = Console.ReadLine();
        SupermarketQueue supermarketQueue = new SupermarketQueue();
        while (commandLine != EndCommand)
        {
            string[] command = commandLine.Split(' ');
            switch (command[0])
            {
                case AppendCommand:
                    supermarketQueue.Append(command[1]);
                    output.AppendLine(OKMessage);
                    break;
                case InsertCommand:
                    if (supermarketQueue.Insert(int.Parse(command[1]), command[2]))
                    {
                        output.AppendLine(OKMessage);
                    }
                    else
                    {
                        output.AppendLine(ErrorMessage);
                    }

                    break;
                case FindCommnad:
                    output.AppendFormat("{0}{1}", supermarketQueue.Find(command[1]), Environment.NewLine);
                    break;
                case ServeCommand:
                    var served = supermarketQueue.Serve(int.Parse(command[1]));
                    if (served != null)
                    {
                        output.AppendLine(string.Join(" ", served));
                    }
                    else
                    {
                        output.AppendLine(ErrorMessage);
                    }

                    break;
            }

            commandLine = Console.ReadLine();
        }

        Console.Write(output);
    }
Example #2
0
    static void Main()
    {
        SupermarketQueue marketQueue = new SupermarketQueue();
        StringBuilder result = new StringBuilder();
        string readLineString = Console.ReadLine();
        string[] readLine = readLineString.Split(' ');
        string command = readLine[0];

        while (command != "End")
        {
            switch (command)
            {
                case "Append":
                    {
                        string name = readLine[1];
                        result.AppendLine(marketQueue.Append(name));
                        break;
                    }
                case "Insert":
                    {
                        int position = int.Parse(readLine[1]);
                        string name = readLine[2];
                        result.AppendLine(marketQueue.Insert(position, name));
                        break;
                    }
                case "Find":
                    {
                        string name = readLine[1];
                        result.AppendLine(marketQueue.Find(name).ToString());
                        break;
                    }
                case "Serve":
                    {
                        int count = int.Parse(readLine[1]);
                        result.AppendLine(marketQueue.Serve(count));
                        break;
                    }
            }

            readLineString = Console.ReadLine();
            readLine = readLineString.Split(' ');
            command = readLine[0];
        }

        Console.WriteLine(result.ToString());
    }