Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using Unit4.CollectionsLib;
- namespace ConsoleApp7
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine("Code starts here");
- Console.WriteLine("");
- Stack<string> YellowContainer = new Stack<string>();
- Stack<string> BlueContainer = new Stack<string>();
- Stack<string> RedContainer = new Stack<string>();
- ContainerBallSorter(YellowContainer);
- Console.WriteLine("The Yellow Container now has: {0}", YellowContainer);
- Console.WriteLine("");
- ContainerBallSorter(BlueContainer);
- Console.WriteLine("The Blue Container now has: {0}", BlueContainer);
- Console.WriteLine("");
- ContainerBallSorter(RedContainer);
- Console.WriteLine("The Red Container now has: {0}", RedContainer);
- Console.WriteLine("");
- }
- public static Stack<string> ContainerBallSorter(Stack<string> Container)
- {
- string YellowBall = "yellow";
- string BlueBall = "blue";
- string RedBall = "red";
- Console.Write("What type of Container is this? (yellow / blue / red): ");
- string ContainerChoice = Console.ReadLine();
- Console.WriteLine("");
- if (ContainerChoice == YellowBall)
- {
- ContainerChoice = YellowBall;
- Console.WriteLine("The Container Type is {0}", ContainerChoice);
- }
- else if (ContainerChoice == BlueBall)
- {
- ContainerChoice = BlueBall;
- Console.WriteLine("The Container Type is {0}", ContainerChoice);
- }
- else if (ContainerChoice == RedBall)
- {
- ContainerChoice = RedBall;
- Console.WriteLine("The Container Type is {0}", ContainerChoice);
- }
- string[] balls = { RedBall, BlueBall, BlueBall, RedBall, YellowBall, YellowBall, BlueBall, RedBall, RedBall, RedBall, BlueBall, BlueBall, YellowBall, RedBall, RedBall, RedBall };
- for (int i = 0; i < balls.Length; i++)
- {
- if (balls[i] == ContainerChoice)
- {
- Container.Push(balls[i]);
- Console.WriteLine("Pushed Ball.");
- }
- else if (balls[i] == ContainerChoice)
- {
- Container.Push(balls[i]);
- Console.WriteLine("Pushed Ball.");
- }
- else if (balls[i] == ContainerChoice)
- {
- Container.Push(balls[i]);
- Console.WriteLine("Pushed Ball.");
- }
- }
- Console.WriteLine(Container);
- Console.WriteLine("");
- // NOTE: PLEASE BE AWARE THAT THE ARRAY DOESNT REMOVE THE ELEMENTS FROM ITSELF AFTER THE STUFF GETS PUSHED.
- return Container;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement