Question
written in c# please :) Stacks and Queues are data structures. A queue is a collection of items stored in a FIFO manner -- First
written in c# please :)
Stacks and Queues are data structures. A queue is a collection of items stored in a FIFO manner -- First one In is the First one Out. This kind of structure would be an excellent way to handle a line of customers waiting to return an item in a store. The first person in line expects to be the first person who gets service. A stack is a collection of items stored in a LIFO manner -- Last one In is First one Out. This is easily visualized with a plate dispenser at a buffet -- a bunch of plates get pushed into the dispenser, and the last one is the one on top, so it is the first one taken.
Both of these structures are created in C# with the same underlying structure, a linked list. In a stack, adding a new item to the stack structure uses an Add At Front method, whereas in a queue, adding a new item to the queue structure uses an Add At End method. In both structures, removing an item takes the item at the front of the structure. When removing, that item need to be assigned to a variable to be able to report or identify which item was removed.
Create a project that demonstrates the C# collection classes for queues and stacks. Using an array of names, add each name to both structures, list the contents of the structures, then remove the contents, displaying which one is being removed. Here is an example:
Create an array for 4 names and initialize it with an initializer list -- they must be different from the sample, and one must be your name.
In a loop, add each name in the array to a queue and report it on the screen. For example, the first name added to the queue appears in the example as "Adding Nancy to queue". In a foreach loop, display all of the names in the queue. In a loop that continues while the count of items in the queue is greater than zero, remove a name from the queue and report it on the screen.
Do the same work with a stack, and notice the differences in the results.
ch 18 Queues and stacks by student Name Queue Adding Nancy to queue Adding Paul to queue Adding Adam to queue Adding Beth to queue The queue contains these names Nancy Paul Adam Beth Removing names from queue Just removed Nancy from queue Just removed Paul from queue Just removed Adam from queue Just removed Beth from queue Stack Adding Nancy to stack Adding Paul to stack Adding Adam to stack Adding Beth to stack The stack contains these names Beth Adam Paul Nancy Removing names from stack Just removed Beth from stack Just removed Adam from stack Just removed Paul from stack Just removed Nancy from stack Press any key to continueStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started