Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Zipinfo
- {
- private char ch;
- private int times;
- public Zipinfo(char c,int t)
- {
- this.ch = c;
- this.times = t;
- }
- public char GetChar()
- {
- return this.ch;
- }
- public int Gettimes()
- {
- return this.times;
- }
- public override string ToString()
- {
- return "<" + this.ch + "> <" + this.times + ">";
- }
- }
- //הפעולות
- public static Node<Zipinfo> Zip (Node<char> lst)
- {
- Node<Zipinfo> p = new Node<Zipinfo>(null),first=p;
- int co = 1;
- while (lst.HasNext())
- {
- if (lst.GetValue() == lst.GetNext().GetValue())
- {
- co++;
- }
- else
- {
- Insert(p, new Zipinfo(lst.GetValue(), co));
- p = p.GetNext();
- co = 1;
- }
- lst = lst.GetNext();
- }
- Insert(p, new Zipinfo(lst.GetValue(), co));
- return first.GetNext();
- }
- public static Node<char> Unzip(Node<Zipinfo> lst)
- {
- int t;
- Node<char> p = new Node<char>('a'),first=p;
- while(lst!=null)
- {
- t =lst.GetValue().Gettimes();
- for (int i=0;i<t;i++)
- {
- Insert(p, lst.GetValue().GetChar());
- p = p.GetNext();
- }
- lst = lst.GetNext();
- }
- return first.GetNext();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement