Beispiel #1
0
        public void add(CObject o)
        {
            if (count != 0)
            {
                CContainerItem c = new CContainerItem(o);
                c.prev = last;
                c.next = first;
                first.prev = c;
                last.next = c;

                last=c;
                current = last;
                count = count + 1;

            }
            else
            {
                first = new CContainerItem(o);
                last = first;
                first.next = last;
                first.prev = last;

                last.next = first;
                last.prev = first;
                current = last;
                count = count + 1;
            }
        }
Beispiel #2
0
 public CContainer()
 {
     current = null;
     first = null;
     last = null;
     count = 0;
 }
Beispiel #3
0
 public CContainerItem(CObject c)
 {
     prev = null;
     next = null;
     obj=c;
 }
Beispiel #4
0
 public void ShiftPrev()
 {
     current = current.prev;
 }
Beispiel #5
0
 public void ShiftNext()
 {
     current = current.next;
 }
Beispiel #6
0
        public void SaveContainer()
        {
            stream = new FileStream("file.txt",FileMode.Truncate,FileAccess.Write);
            StreamWriter sw = new StreamWriter(stream);
            current = first;
            int ct = count;
            sw.WriteLine(count);
            sw.Flush();
            while (ct != 0)
            {
                current.obj.SaveObject(stream);
                ShiftNext();
                ct = ct - 1;
            }

            stream.Close();
        }
Beispiel #7
0
        public void Remove()
        {
            if (count != 0)
            {
                if (current == first)
                {
                    if (count == 1)
                    {
                        first = null;
                        current = null;
                        last = first;
                        count = 0;
                    }
                    else
                    {
                        first = first.next;
                        first.prev = last;
                        count = count - 1;
                    }
                }
                else
                {
                    if (current == last)
                    {
                        if (count == 1)
                        {
                            first = null;
                            current = null;
                            last = first;
                            count = 0;
                        }
                        else
                        {
                            last = last.prev;
                            current = last;
                            last.next = first;
                            count = count - 1;
                        }

                    }
                    else
                    {
                        CContainerItem temp;
                        temp = current;
                        current = current.prev;
                        current.next = temp.next;
                        current = temp.next;
                        current.prev = temp.prev;
                        count = count - 1;
                    }
                }
            }
        }