Advertisement
chipsi2

zip/unzip שרשרת

Dec 25th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.68 KB | None | 0 0
  1.  class Zipinfo
  2.     {
  3.         private char ch;
  4.         private int times;
  5.         public Zipinfo(char c,int t)
  6.         {
  7.             this.ch = c;
  8.             this.times = t;
  9.         }
  10.         public char GetChar()
  11.         {
  12.             return this.ch;
  13.         }
  14.         public int Gettimes()
  15.         {
  16.             return this.times;
  17.         }
  18.         public override string ToString()
  19.         {
  20.             return "<" + this.ch + "> <" + this.times + ">";
  21.         }
  22.     }
  23. //הפעולות
  24.   public static Node<Zipinfo> Zip (Node<char> lst)
  25.         {
  26.             Node<Zipinfo> p = new Node<Zipinfo>(null),first=p;
  27.             int co = 1;
  28.             while (lst.HasNext())
  29.             {    
  30.                 if (lst.GetValue() == lst.GetNext().GetValue())
  31.                 {
  32.                     co++;
  33.                 }
  34.                 else
  35.                 {
  36.                     Insert(p, new Zipinfo(lst.GetValue(), co));
  37.                     p = p.GetNext();
  38.                     co = 1;
  39.                 }
  40.                 lst = lst.GetNext();
  41.             }
  42.             Insert(p, new Zipinfo(lst.GetValue(), co));
  43.             return first.GetNext();
  44.  
  45.         }
  46.         public static Node<char> Unzip(Node<Zipinfo> lst)
  47.         {
  48.             int t;
  49.             Node<char> p = new Node<char>('a'),first=p;
  50.             while(lst!=null)
  51.             {
  52.                 t =lst.GetValue().Gettimes();
  53.                 for (int i=0;i<t;i++)
  54.                 {
  55.                     Insert(p, lst.GetValue().GetChar());
  56.                     p = p.GetNext();
  57.                 }
  58.                 lst = lst.GetNext();
  59.             }
  60.             return first.GetNext();
  61.          
  62.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement