Advertisement
Egonau

Untitled

Oct 22nd, 2020
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.73 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Stackc
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int[] stack1 = new int[100000];
  10.            
  11.             string[] com;
  12.             int first = 49999;
  13.             int last = 50000;
  14.             while (true)
  15.             {
  16.                 com = Console.ReadLine().Split();
  17.                 if (com[0] == "push_back")
  18.                 {
  19.                     stack1[last] = int.Parse(com[1]);
  20.                     last++;
  21.                     Console.WriteLine("ok");
  22.                 }
  23.                 if (com[0] == "push_front")
  24.                 {
  25.                     stack1[first] = int.Parse(com[1]);
  26.                     first--;
  27.                     Console.WriteLine("ok");
  28.                 }
  29.                 if (com[0] == "pop_front")
  30.                 {
  31.                     if (last - first > 1)
  32.                     {
  33.                         first++;
  34.                         Console.WriteLine(stack1[first]);
  35.                     }
  36.                     else Console.WriteLine("error");
  37.  
  38.  
  39.                 }
  40.                 if (com[0] == "pop_back")
  41.                 {
  42.                     if (last - first > 1)
  43.                     {
  44.                         last--;
  45.                         Console.WriteLine(stack1[last]);
  46.                     }
  47.                     else Console.WriteLine("error");
  48.  
  49.                    
  50.                        
  51.                    
  52.  
  53.                 }
  54.                 if (com[0] == "front")
  55.                 {
  56.  
  57.                     if (last - first > 1)
  58.                     {
  59.                         Console.WriteLine(stack1[first+1]);
  60.                     }
  61.                     else Console.WriteLine("error");
  62.  
  63.                    
  64.                    
  65.                    
  66.                    
  67.  
  68.                 }
  69.                 if (com[0] == "back")
  70.                 {
  71.                     if (last - first > 1)
  72.                     {
  73.                          Console.WriteLine(stack1[last - 1]);
  74.                     }
  75.                     else Console.WriteLine("error");
  76.  
  77.                    
  78.                    
  79.  
  80.  
  81.  
  82.                 }
  83.                 if (com[0] == "size")
  84.                 {
  85.                     Console.WriteLine(last-first-1);
  86.                    
  87.  
  88.                 }
  89.                 if (com[0] == "clear")
  90.                 {
  91.                     last = 50000;
  92.                     first = last-1;
  93.                    
  94.                         Console.WriteLine("ok");
  95.                        
  96.                 }
  97.  
  98.                 if (com[0] == "exit")
  99.                 {
  100.                     Console.WriteLine("bye");
  101.                     break;
  102.                 }
  103.             }
  104.         }
  105.     }
  106. }
  107.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement