What's new

Help po sa Exam hanggang Sunday (12/06/20)

CkVal20

Enthusiast
Joined
Nov 22, 2020
Posts
24
Reaction
3
Points
36
Age
23
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;
}
}
}
Screenshot_20201203_145618_com.moodle.moodlemobile.jpg
 

Attachments

Similar threads

Back
Top