Can you answer this queue act?

Jayliepedraza 1 Reputation point
2021-01-28T15:13:12.457+00:00
  1. Accept characters using the Implementation of Array Structure, then save it to Queue.
  2. If the value to be stored in the queue is equivalent to input of the user, count and display its occurrence.
  3. Count the total values inputted by the user.
  4. If the user inputted his magic number, the program will stop then display its Front and Rear value and the total value of input (e.g. letter "t").

Sample Output:
Find: t
Input character: d
Continue? N/n or Y/y : Y
Input character: a
Continue? N/n or Y/y : Y
Input character: t
Continue? N/n or Y/y : Y
Input character: a
.
.
.
Input character: c
Input character: t

Continue? N/n or Y/y : n
Queue Collection: t c u r t s a t a d
t Count : 3
Collection Count: 10
Front value: d
Rear value: t

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,842 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Timon Yang-MSFT 9,591 Reputation points
    2021-01-29T02:12:59.47+00:00

    This is a bit like homework, so I will try to express what I mean in words rather than complete code.

    No need to use an array, just use Queue<T> Class directly, please take a look at Queue<T>.Enqueue(T) Method.

    There is no need to reuse the same code to remind the user and get the input, put it in a while loop, the loop condition is the magic number.

    After the loop is over, you can use linq to get the head and tail elements and other required information, for example:

                var re = myQueue.Where(x => x == "t").Count();// re = 3  
    

    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.