示例#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;
            }
        }
示例#2
0
 public CContainer()
 {
     current = null;
     first = null;
     last = null;
     count = 0;
 }
示例#3
0
 public CContainerItem(CObject c)
 {
     prev = null;
     next = null;
     obj=c;
 }
示例#4
0
 public void ShiftPrev()
 {
     current = current.prev;
 }
示例#5
0
 public void ShiftNext()
 {
     current = current.next;
 }
示例#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();
        }
示例#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;
                    }
                }
            }
        }