Exemplo n.º 1
0
 public bool deleteTask(Task x)
 {
     /****
      * This function will delete a Task from the hash table
      ****/
     if(!Contains(x)) { return false; } //If the task is not in the hash table is cannot be deleted
     int hash_val = 0;
     hash_val = x.getHashCode();
     for(int i = 0; i < hashtable[hash_val].Count; i++){
         hashtable[hash_val][i] = null;
         count--; //Decrement the size of the hash table
     }
     return true;
 }
Exemplo n.º 2
0
 public bool Contains(Task x)
 {
     /****
      * This function will check the hashtable by indexing to the bucket based off of the hash code for the task being
      * inserted and checking all the tasks that reside in that bucket.
      ****/
     int hash_val = 0;
     hash_val = x.getHashCode();
     for(int i = 0; i < hashtable[hash_val].Count; i++){ //loop through the bucket to check for x
         if(x == hashtable[hash_val][i])
             return true; //The task is already in the hash table
     }
     return false;
 }
Exemplo n.º 3
0
 public bool insert(Task x)
 {
     /****
      * This function will check to make sure the task you are trying to add to the hash table is not already in the
      * table by calling the contains function. If it is not already in the hash table then this function will
      * insert the new task into your calendar.
      ****/
     if(Contains(x) == true) return false;
     int hash_val = 0;
     hash_val = x.getHashCode();
     for(int i = 0; i < hashtable[hash_val].Count; i++)
         hashtable[hash_val][i] = x;
     count++; //Increment the size of the hash table
     return true;
 }
Exemplo n.º 4
0
 public static void Main()
 {
     Task Task1 = new Task("Nik's Birthday", 10, 18, 12, 1994);
     Task1.PrintTask();
     Console.ReadKey(true); //for console
 }
Exemplo n.º 5
0
 public static void Main()
 {
     //Task(string, int LvlofImportance, int Month, int Day, int Year, int EndMonth, int EndDay, int EndYear)
     Task Task1 = new Task("Birthday", 10, 12, 30, 2014, 0, 0, 0);
     Task Task2 = new Task("Birthday", 10, 3, 12, 1994, 0, 0, 0);
     Task Task3 = new Task("Tito's Party", 10, 5, 7, 2015, 0, 0, 0);
     Task Task4 = new Task("Dentist", 10, 10, 18, 2014, 0, 0, 0);
     Console.WriteLine("Begin Testing: ");
     if (Task1 < Task2){
     Console.WriteLine("Today comes first"); //Today = Task1
     }
     else if (Task1 > Task2){
     Console.WriteLine("Date2 comes first"); //Date2 = Task2
     }
     else if (Task1 == Task2){
     Console.WriteLine("Date1 and Date2 are equal");
     }
     if (Task1 != Task2){
     Console.WriteLine("The dates are not equal");
     }
     openHashTable Hash = new openHashTable();
     int sizeBefore, sizeAfter;
     sizeBefore = Hash.getCount();
     Console.WriteLine("The size of the table before insert is: {0}", sizeBefore);
     Hash.insert(Task1); //Check inserts
     Hash.insert(Task2);
     Hash.insert(Task3);
     Hash.insert(Task4);
     sizeAfter = Hash.getCount(); //Check to make sure inserts are working. Count can be used for checking
                              //because it is only incremented and decremented in the insert and delete
                              //functions.
     Console.WriteLine("The size of the table after insert is: {0}", sizeAfter);
     Hash.deleteTask(Task4); //Check deleteTask
     bool containsTask;
     containsTask = Hash.Contains(Task2);
     if(containsTask == true) //Check Contains function
     Console.WriteLine("Hash contains Task2");
     Console.WriteLine("The size of the table after delete is: {0}", sizeAfter);
     Console.WriteLine("The hash value for Task1 is: {0}", Task1.HashCode);
     Console.WriteLine("The hash value for Task2 is: {0}", Task2.HashCode);
     Console.WriteLine("The hash value for Task3 is: {0}", Task3.HashCode);
     Console.WriteLine("The hash value for Task4 is: {0}", Task4.HashCode);
     //End testing
     Console.WriteLine("End Testing:");
     Console.ReadKey(true); //for console
 }