/// <summary> /// Puts a key:value pair into a bucket at the hashed index of key /// </summary> /// <param name="key"> key </param> /// <param name="value"> value </param> public void Set(T key, T value) { int hashKey = Hash(key); if (Map[hashKey] == null) { Map[hashKey] = new DataStructures.LinkedList <KeyValuePair <T, T> >(); } KeyValuePair <T, T> entry = new KeyValuePair <T, T>(key, value); Map[hashKey].Insert(entry); counter++; }
static void Main(string[] args) { var MainList = new DataStructures.LinkedList<int>(); MainList.Insert(1); MainList.Insert(2); MainList.Insert(3); foreach (int item in MainList.ToArray()) { Console.WriteLine("Number: " + item); } }
public static bool HasCycle(DataStructures.LinkedList <int> list) { List <Node <int> > listNodes = new List <Node <int> >(); Node <int> curNode = list.Head; while (curNode.Next != null) { if (listNodes.Contains(curNode.Next)) { return(true); } else { listNodes.Add(curNode.Next); } curNode = curNode.Next; } return(false); }
static void Main(string[] args) { DataStructures.LinkedList <int> ll = new DataStructures.LinkedList <int>(); ll.Add(8); ll.Add(12); ll.Add(8); ll.Add(4); ll.Add(21); ll.Print(); CrackingCodingInterview.RemoveDuplicates(ll); ll.Print(); //bool isUnique = CrackingCodingInterview.isUniqueWithHashTable("asdfjkl;"); //Console.WriteLine("Is string unique: " + isUnique); //HackerRankChallenges.miniMaxSum(new List<int> { 1, 3, 5, 7, 9 }); }
//Chapter 2 LinkedLists public static DataStructures.LinkedList <int> RemoveDuplicates(DataStructures.LinkedList <int> ll) { Node <int> curNode = ll.Head; Node <int> trailNode = null; List <int> cacheList = new List <int>(); while (curNode != null) { if (cacheList.Contains(curNode.Value)) { RemoveNode(curNode, trailNode); } else { cacheList.Add(curNode.Value); trailNode = curNode; } curNode = curNode.Next; } return(ll); }