标题:链表中!出现这问题!
只看楼主
jay520
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2011-2-11
结帖率:83.33%
已结贴  问题点数:10 回复次数:7 
链表中!出现这问题!
当前上下文不存在GetByIndex!
搜索更多相关主题的帖子: 上下文 
2011-03-21 11:32
zhp223
Rank: 5Rank: 5
等 级:职业侠客
帖 子:99
专家分:362
注 册:2010-3-21
得分:0 
问题描述不清,至少要贴点代码呀

日有所思,夜有所梦
2011-03-21 12:01
qq1023569223
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:湖南科技大学
等 级:贵宾
威 望:26
帖 子:2753
专家分:13404
注 册:2010-12-22
得分:0 
这样怎么帮你啊?

   唯实惟新 至诚致志
2011-03-21 12:25
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
hqflfd
Rank: 1
等 级:新手上路
帖 子:2
专家分:5
注 册:2011-3-22
得分:5 
MemoryUnit PrevNode = GetByIndex(index - 1)
2011-03-22 23:32
hqflfd
Rank: 1
等 级:新手上路
帖 子:2
专家分:5
注 册:2011-3-22
得分:0 
没定义GetByIndex方法吧
2011-03-22 23:32
zhp223
Rank: 5Rank: 5
等 级:职业侠客
帖 子:99
专家分:362
注 册:2010-3-21
得分:5 
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;
         }
方法名错了吧,GetByIndex

日有所思,夜有所梦
2011-03-23 11:53
vxbb
Rank: 6Rank: 6
等 级:侠之大者
帖 子:163
专家分:440
注 册:2008-8-18
得分:0 
方法名错了  GetByUndex
出这样的错,莫非是全手工敲的代码?

QQ:491697374  Mail:vxbb@
2011-03-23 13:57



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-334289-1-1.html




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

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