Advertisement
callumbinner22

self built queue ##inprogress

Dec 12th, 2016
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.10 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApplication51
  8. {
  9.     class Program
  10.     {
  11.         int x;
  12.         static string[] thequeue = new string[11];
  13.         static int frontpointer = 0;
  14.         static int rearpointer = -1;
  15.  
  16.         static void Main(string[] args)
  17.         {
  18.             int x =0;
  19.             while (x<1)
  20.             {
  21.                 int input;
  22.            
  23.                Console.WriteLine(" 1) Add New Customer");
  24.                 Console.WriteLine(" 2) Check Next Customer to Be Served ");
  25.                 Console.WriteLine(" 3) Serve Next Customer ");
  26.                 input = Convert.ToInt32(Console.ReadLine());
  27.  
  28.                
  29.                 if (input == 1)
  30.                 {
  31.                     Console.WriteLine("Please enter customer name");
  32.  
  33.                     enqueue(Console.ReadLine());
  34.                 }
  35.  
  36.                 if (input == 2)
  37.                 {
  38.                     Console.WriteLine("The latest customer is ... " + peek());
  39.                 }
  40.  
  41.                 if (input == 3)
  42.                 {
  43.                     Console.WriteLine("Serving the next customer " + dequeue());
  44.  
  45.                 }
  46.                 Console.WriteLine("Would you like to continue?");
  47.                 string decision = Console.ReadLine();
  48.                 if (decision == "yes")
  49.                 {
  50.                     x = 0;
  51.                 }
  52.                 else if (decision == "no")
  53.                 {
  54.                     x = 1;
  55.                 }
  56.  
  57.             }
  58.         }
  59.  
  60.         static void enqueue (string item)
  61.         {
  62.  
  63.            
  64.             rearpointer++;
  65.             thequeue[rearpointer%10] = item;
  66.         }
  67.  
  68.         static string dequeue()
  69.         {
  70.             string item;
  71.             item = thequeue[frontpointer%10];
  72.             thequeue[frontpointer] = "";
  73.             frontpointer++;
  74.             return thequeue[frontpointer];
  75.            
  76.         }
  77.         static string peek()
  78.     {
  79.         return thequeue[frontpointer];
  80.     }
  81.  
  82.  
  83.     }
  84.  
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement