Ito po codes ko kaso dami Error:
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
namespace CSharp_Shell
{
public static class Program
{
public static void Main()
{
HashTable Func = new HashTable();
Func.AddItem("1","asd");
Func.GetKeys();
Func.GetItems();
Console.Write(Func.Count);
}
}
public class HashTable
{
public KeyItems[] keyitems;
public int length;
public int count;
public HashTable()
{
keyitems =new KeyItems[100];
length = keyitems.Length;
count = 0;
}
public void AddItem(object key, object item)
{
int Hashval = GetHashVal(key);
if(keyitems[Hashval].items.Equals(!null))
{
keyitems[Hashval].keys = key;
keyitems[Hashval].items = item;
count++;
}
else
for(int i=1;i<length; i++)
{
if(keyitems[(i+Hashval)%length].items.Equals(!null))
{
keyitems[(i+Hashval)%length].keys=key;
keyitems[(i+Hashval)%length].items=item;
count++;
break;
}
}
}
public void RemoveItem(object key)
{
count--;
}
public bool ContainValue(object item)
{
return false;
}
public bool ContainKey(object key)
{
return false;
}
public int Count
{
get
{
return count;
}
}
public void GetKeys()
{
for(int i=0; i<length; i++)
{
Console.WriteLine("Keys: "+keyitems.keys);
}
}
public void GetItems()
{
for(int i=0; i<length; i++)
{
Console.WriteLine("Items: "+keyitems.items);
}
}
//Get the Hash Value of keys
public int GetHashVal(object key)
{
return key.GetHashCode() % length;
}
}
public class KeyItems
{
public object keys, items;
public KeyItems()
{
keys = null;
items = null;
}
}
}
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
namespace CSharp_Shell
{
public static class Program
{
public static void Main()
{
HashTable Func = new HashTable();
Func.AddItem("1","asd");
Func.GetKeys();
Func.GetItems();
Console.Write(Func.Count);
}
}
public class HashTable
{
public KeyItems[] keyitems;
public int length;
public int count;
public HashTable()
{
keyitems =new KeyItems[100];
length = keyitems.Length;
count = 0;
}
public void AddItem(object key, object item)
{
int Hashval = GetHashVal(key);
if(keyitems[Hashval].items.Equals(!null))
{
keyitems[Hashval].keys = key;
keyitems[Hashval].items = item;
count++;
}
else
for(int i=1;i<length; i++)
{
if(keyitems[(i+Hashval)%length].items.Equals(!null))
{
keyitems[(i+Hashval)%length].keys=key;
keyitems[(i+Hashval)%length].items=item;
count++;
break;
}
}
}
public void RemoveItem(object key)
{
count--;
}
public bool ContainValue(object item)
{
return false;
}
public bool ContainKey(object key)
{
return false;
}
public int Count
{
get
{
return count;
}
}
public void GetKeys()
{
for(int i=0; i<length; i++)
{
Console.WriteLine("Keys: "+keyitems.keys);
}
}
public void GetItems()
{
for(int i=0; i<length; i++)
{
Console.WriteLine("Items: "+keyitems.items);
}
}
//Get the Hash Value of keys
public int GetHashVal(object key)
{
return key.GetHashCode() % length;
}
}
public class KeyItems
{
public object keys, items;
public KeyItems()
{
keys = null;
items = null;
}
}
}
Attachments
-
You do not have permission to view the full content of this post. Log in or register now.