Advertisement
double_trouble

interface(shift)

Jun 19th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.26 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ConsoleApplication11
  7. {
  8.     interface left
  9.     {
  10.         char[] shift();
  11.     }
  12.  
  13.     interface right
  14.     {
  15.         char[] shift();
  16.     }
  17.  
  18.     class MyClass:right, left
  19.     {
  20.         char[] m;
  21.         public MyClass(char[] ar)
  22.         {
  23.             m = new char[ar.Length];
  24.             m = ar;
  25.         }
  26.  
  27.         char[] left.shift()
  28.         {
  29.             char item = m[0];
  30.             char[] nc = new char[m.Length];
  31.             for (int i = 1; i < m.Length; i++)
  32.                 nc[i - 1] = m[i];
  33.             nc[m.Length - 1] = item;
  34.             return nc;
  35.         }
  36.  
  37.         char[] right.shift()
  38.         {
  39.             char item = m[m.Length - 1];
  40.             char[] nc = new char[m.Length];
  41.             for (int i = m.Length - 1; i > 0; i--)
  42.                 nc[i] = m[i - 1];
  43.             nc[0] = item;
  44.             return nc;
  45.         }
  46.     }
  47.  
  48.     class Program
  49.     {
  50.         static void Main(string[] args)
  51.         {
  52.             MyClass arr = new MyClass(new char[]{ '0', '1', '2'});
  53.             left l = arr;
  54.             right r = arr;
  55.             Console.WriteLine(l.shift());
  56.             Console.WriteLine(r.shift());
  57.         }
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement