| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 373 人关注过本帖
标题:链表中!出现这问题!
取消只看楼主 加入收藏
jay520
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2011-2-11
结帖率:83.33%
收藏
已结贴  问题点数:10 回复次数:1 
链表中!出现这问题!
当前上下文不存在GetByIndex!
搜索更多相关主题的帖子: 上下文 
2011-03-21 11:32
jay520
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2011-2-11
收藏
得分:0 
我在弄虚拟线性表!代码很多!那就复制出错误的一个吧!using System;
using System.Drawing;

namespace WindowsApplication1
{
    public class LinkedList
    {
        private int count;
        private MemoryUnit _head;
        private Heap _heap;
        private Color _background;

        public LinkedList(Heap heap, Color color)
        {
            _heap = heap;
            _background = color;
        }
        public void Add(string value)
        {
            MemoryUnit newNode = _heap.NewUnit(_background);
            newNode.Value = value;
            if (_head == null)
            {
                _head = newNode;
            }
            else
            {
                GetByIndex(count - 1).Next = newNode;                                                   
            }
            count++;
        }
        public void Insert(int index, string value)
        {
            MemoryUnit newNode = _heap.NewUnit(_background);
            newNode.Value = value;
            if (index == 0)
            {
                if (_head == null)
                {
                    _head = newNode;
                }
                else
                {
                    newNode.Next = _head;
                    _head = newNode;
                }
            }
            else
            {
                MemoryUnit PrevNode = GetByIndex(index - 1);
                MemoryUnit nextNode = PrevNode.Next;
                PrevNode.Next = newNode;
                newNode.Next = nextNode;
            }
            count++;
        }
        public void RemoveAt(int index)
        {
            if (index == 0)
            {
                _head.SetUnuse();
                _head = _head.Next;
            }
            else
            {
                MemoryUnit prevNode = GetByIndex(index - 1);
                if (prevNode.Next == null)
                {
                    throw new ArgumentOutOfRangeException("索引超出范围");
                }
                prevNode.Next.SetUnuse();
                prevNode.Next = prevNode.Next.Next;
            }
            count--;
        }
        private MemoryUnit GetByUndex(int index)
         {
             if((index<0)||(index>=this.count))
             {
                 throw new ArgumentOutOfRangeException("索引超出范围");
             }
             MemoryUnit tempNode=this._head;
             for(int i=0;i<index;i++)
             {
                 tempNode=tempNode.Next;
             }
             return tempNode;
         }
    }
}
2011-03-22 08:23
快速回复:链表中!出现这问题!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011201 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved