class myHashtable
{
public Hashtable htResult = new Hashtable();
public void AddItem(int _intNewItem)
{
int pkey = _intNewItem % 13;
int i = 0;
while (this.htResult.Contains(pkey) && i < 13)
{
pkey = (pkey + 1) % 13;
i++;
}
if (i < 13)
this.htResult.Add(pkey, _intNewItem);
else
Console.WriteLine("哈希表溢出");
}
} class Program
{
static void Main(string[] args)
{
myHashtable myht = new myHashtable();
int pValue = 0;
Console.WriteLine("输入10个整数值"); for (int i = 0; i < 10; i++)
{
pValue = Convert.ToInt32(Console.ReadLine());
myht.AddItem(pValue); //这行有错误
}
foreach (System.Collections.DictionaryEntry pair in myht.htResult)
{
Console.WriteLine("{0}->[1}", pair.Key, pair.Value);
}
}
}
大家帮忙找一下
谢谢~
{
public Hashtable htResult = new Hashtable();
public void AddItem(int _intNewItem)
{
int pkey = _intNewItem % 13;
int i = 0;
while (this.htResult.Contains(pkey) && i < 13)
{
pkey = (pkey + 1) % 13;
i++;
}
if (i < 13)
this.htResult.Add(pkey, _intNewItem);
else
Console.WriteLine("哈希表溢出");
}
} class Program
{
static void Main(string[] args)
{
myHashtable myht = new myHashtable();
int pValue = 0;
Console.WriteLine("输入10个整数值"); for (int i = 0; i < 10; i++)
{
pValue = Convert.ToInt32(Console.ReadLine());
myht.AddItem(pValue); //这行有错误
}
foreach (System.Collections.DictionaryEntry pair in myht.htResult)
{
Console.WriteLine("{0}->[1}", pair.Key, pair.Value);
}
}
}
大家帮忙找一下
谢谢~
解决方案 »
- 【急啊】向大侠们求助
- 有没有软件可以比较两个字符串,得到两个字符串相同的部分?
- 很奇怪的使用DataRow出现索引超出范围的异常
- [讨论]outlook 实时邮件监控程序设计
- WinForms系统异常处理
- 情老手赐教:在我用C++写的DLL中如何接收别人用C#写的UI传进来的参数,内详
- 毕业设计中遇到的问题,剪贴板的问题,谢谢各位了。
- winform下的datagrid问题请教
- 大家帮我看看一个三层结构的实际的项目中的问题如何解决?
- 有n个位置,每个位置可取3个值,问有多少可能性?
- VS2005关于resx的相关操作,请用过resx的高人进
- 线程间操作, 如何把线程里的数据打出来。贴出代码, 请各位指点!
for (int i = 0; i < 10; i++)
{
pValue = Convert.ToInt32(Console.ReadLine());
myht.AddItem(pValue); //这行有错误
}
这个for循环你是想循环找到输入的10个整数值,是吗?但是这样写根本行不通啊
string str = Console.ReadLine();
string[] arrStr = str.Split(',');
for (int i = 0; i < 10; i++)
{
pValue = Convert.ToInt16(arrStr[i]);
}
这个可以取得输入的10个数字,但是你写的AddItem()有误,不是很明白你的意思
foreach (System.Collections.DictionaryEntry pair in myht.htResult)
似乎是这句的问题,
提示,输入的字符串格式不对。
myht.htResult总觉得这句很怪
{
Console.WriteLine("{0}-> [1}", pair.Key, pair.Value);
}
这里错了,但是为什么提示报告错了呢?