Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Stackc
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] stack1 = new int[100000];
- string[] com;
- int first = 49999;
- int last = 50000;
- while (true)
- {
- com = Console.ReadLine().Split();
- if (com[0] == "push_back")
- {
- stack1[last] = int.Parse(com[1]);
- last++;
- Console.WriteLine("ok");
- }
- if (com[0] == "push_front")
- {
- stack1[first] = int.Parse(com[1]);
- first--;
- Console.WriteLine("ok");
- }
- if (com[0] == "pop_front")
- {
- if (last - first > 1)
- {
- first++;
- Console.WriteLine(stack1[first]);
- }
- else Console.WriteLine("error");
- }
- if (com[0] == "pop_back")
- {
- if (last - first > 1)
- {
- last--;
- Console.WriteLine(stack1[last]);
- }
- else Console.WriteLine("error");
- }
- if (com[0] == "front")
- {
- if (last - first > 1)
- {
- Console.WriteLine(stack1[first+1]);
- }
- else Console.WriteLine("error");
- }
- if (com[0] == "back")
- {
- if (last - first > 1)
- {
- Console.WriteLine(stack1[last - 1]);
- }
- else Console.WriteLine("error");
- }
- if (com[0] == "size")
- {
- Console.WriteLine(last-first-1);
- }
- if (com[0] == "clear")
- {
- last = 50000;
- first = last-1;
- Console.WriteLine("ok");
- }
- if (com[0] == "exit")
- {
- Console.WriteLine("bye");
- break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement