Advertisement
Weewee21

BallSorterIntoContainers_LISQ_And_List_Array_ExternalFunction

Oct 20th, 2021
1,027
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.04 KB | None | 0 0
  1. using System;
  2. using Unit4.CollectionsLib;
  3.  
  4. namespace ConsoleApp7
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             Console.WriteLine("Code starts here");
  11.             Console.WriteLine("");
  12.  
  13.             Stack<string> YellowContainer = new Stack<string>();
  14.             Stack<string> BlueContainer = new Stack<string>();
  15.             Stack<string> RedContainer = new Stack<string>();
  16.  
  17.             ContainerBallSorter(YellowContainer);
  18.  
  19.             Console.WriteLine("The Yellow Container now has: {0}", YellowContainer);
  20.  
  21.             Console.WriteLine("");
  22.  
  23.             ContainerBallSorter(BlueContainer);
  24.  
  25.             Console.WriteLine("The Blue Container now has: {0}", BlueContainer);
  26.  
  27.             Console.WriteLine("");
  28.  
  29.             ContainerBallSorter(RedContainer);
  30.  
  31.             Console.WriteLine("The Red Container now has: {0}", RedContainer);
  32.  
  33.             Console.WriteLine("");
  34.  
  35.  
  36.  
  37.         }
  38.         public static Stack<string> ContainerBallSorter(Stack<string> Container)
  39.         {
  40.  
  41.             string YellowBall = "yellow";
  42.  
  43.             string BlueBall = "blue";
  44.  
  45.             string RedBall = "red";
  46.  
  47.             Console.Write("What type of Container is this? (yellow / blue / red): ");
  48.             string ContainerChoice = Console.ReadLine();
  49.  
  50.             Console.WriteLine("");
  51.  
  52.             if (ContainerChoice == YellowBall)
  53.             {
  54.                 ContainerChoice = YellowBall;
  55.                 Console.WriteLine("The Container Type is {0}", ContainerChoice);
  56.             }
  57.  
  58.             else if (ContainerChoice == BlueBall)
  59.             {
  60.                 ContainerChoice = BlueBall;
  61.                 Console.WriteLine("The Container Type is {0}", ContainerChoice);
  62.             }
  63.  
  64.             else if (ContainerChoice == RedBall)
  65.             {
  66.                 ContainerChoice = RedBall;
  67.                 Console.WriteLine("The Container Type is {0}", ContainerChoice);
  68.             }
  69.  
  70.             string[] balls = { RedBall, BlueBall, BlueBall, RedBall, YellowBall, YellowBall, BlueBall, RedBall, RedBall, RedBall, BlueBall, BlueBall, YellowBall, RedBall, RedBall, RedBall };
  71.  
  72.             for (int i = 0; i < balls.Length; i++)
  73.             {
  74.                 if (balls[i] == ContainerChoice)
  75.                 {
  76.                     Container.Push(balls[i]);
  77.                     Console.WriteLine("Pushed Ball.");
  78.                 }
  79.  
  80.                 else if (balls[i] == ContainerChoice)
  81.                 {
  82.                     Container.Push(balls[i]);
  83.                     Console.WriteLine("Pushed Ball.");
  84.                 }
  85.  
  86.                 else if (balls[i] == ContainerChoice)
  87.                 {
  88.                     Container.Push(balls[i]);
  89.                     Console.WriteLine("Pushed Ball.");
  90.                 }
  91.             }
  92.  
  93.             Console.WriteLine(Container);
  94.  
  95.             Console.WriteLine("");
  96.  
  97.             // NOTE: PLEASE BE AWARE THAT THE ARRAY DOESNT REMOVE THE ELEMENTS FROM ITSELF AFTER THE STUFF GETS PUSHED.
  98.  
  99.             return Container;
  100.         }
  101.     }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement