Question

Explain the concept of Linked hash table and Write a program in C# where you implement...

Explain the concept of Linked hash table and Write a program in C# where you implement the concept of linked hash table

0 0
Add a comment Improve this question Transcribed image text
Answer #1

LinkedHashTable is just like HashTable with an additional feature of maintaining an order of elements inserted into it. HashTable provided the advantage of quick insertion, search and deletion but it never maintained the track and order of insertion which the LinkedHashTable provides where the elements can be accessed in their insertion order. Few important features of LinkedHashTable are as follows:

    A LinkedHashTable contains values based on the key. It implements the Table interface and extends HashTable class.
    It contains only unique elements .
    It may have one null key and multiple null values .
    It is same as HashTable with additional feature that it maintains insertion order. For example, when we ran the code with HashTable, we got different order of elements

C# program to implement linked Hash Table

using System;

using System.Collections;

class GFG {

    // Main Method
    static public void Main()
    {

        // Create a hashtable
        // Using Hashtable class
        Hashtable my_hashtable1 = new Hashtable();

        // Adding key/value pair
        // in the hashtable
        // Using Add() method
        my_hashtable1.Add("A1", "Welcome");
        my_hashtable1.Add("A2", "to");
        my_hashtable1.Add("A3", "GeeksforGeeks");

        Console.WriteLine("Key and Value pairs from my_hashtable1:");

        foreach(DictionaryEntry ele1 in my_hashtable1)
        {
            Console.WriteLine("{0} and {1} ", ele1.Key, ele1.Value);
        }

        // Create another hashtable
        // Using Hashtable class
        // and adding key/value pairs
        // without using Add method
        Hashtable my_hashtable2 = new Hashtable() {
                                      {1, "hello"},
                                          {2, 234},
                                        {3, 230.45},
                                         {4, null}};

        Console.WriteLine("Key and Value pairs from my_hashtable2:");

        foreach(var ele2 in my_hashtable2.Keys)
        {
            Console.WriteLine("{0}and {1}", ele2,
                            my_hashtable2[ele2]);
        }
    }

Add a comment
Know the answer?
Add Answer to:
Explain the concept of Linked hash table and Write a program in C# where you implement...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT