Advertisement
callumbinner22

Stacks Task 2

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