public static void SelectionMethod() { Console.WriteLine("Please select"); Console.WriteLine("Data Structure: \n 1 : Big O(n) \n 2 : Array \n 3 : Linked List \n 4 : Stack \n 7 : Factorial recursion \n 8 : Fibonacci \n 9 : ReverseString (Recursion) \n 10 : Bubble Sort \n 11 : Selection Sort \n 12 : Insertion Sort"); Console.Write("Please enter your selection: "); string str = Console.ReadLine(); switch (str) { case "1": BigOn.Call100(); break; case "2": DSArray.ChooseArray(); break; case "3": LinkedList linkedList = new LinkedList(5); linkedList.LinkListOperation(); break; case "4": Stack stack = new Stack(); stack.StackOperation(); break; case "7": Factorial fact = new Factorial(); fact.FindFactorial(); break; case "8": Fibonacci fibonacci = new Fibonacci(); fibonacci.FindFibonacci(); break; case "9": ReverseString rev = new ReverseString(); rev.RevString(); break; case "10": BubbleSort bubble = new(); bubble.BubbleSorting(); break; case "11": SelectionSort selection = new(); selection.SortSelection(); break; case "12": InsertionSort insertion = new(); insertion.Insertion(); break; } }
// Concatenates the list of strings into a single string of comma separated types /*private string GetTypesHelper(List<string> types) * { * string type = ""; * foreach(string s in types) * { * if(string.IsNullOrEmpty(type)) * type = s; * else * type += "," + s; * } * return type; * }*/ /*private string GetAssembly(StackValue sv) * { * if (sv.IsObject()) * { * ClassNode classNode = core.ClassTable.ClassNodes[(int)sv.metaData.type]; * assemblyName = classNode.ExternLib; * * } * else if (sv.IsArray) * { * assemblyName = GetTypesHelper(); * } * return assemblyName; * }*/ // Returns a list of unique types in the input array //private List<string> GetArrayTypes(StackValue svData) private Dictionary <string, List <string> > GetArrayTypes(StackValue svData) { Dictionary <string, List <string> > asmTypes = new Dictionary <string, List <string> >(); //List<string> types = new List<string>(); Validity.Assert(svData.IsArray); DSArray hs = runtimeCore.RuntimeMemory.Heap.ToHeapObject <DSArray>(svData); foreach (var sv in hs.VisibleItems) { if (sv.IsArray) { Dictionary <string, List <string> > types = GetArrayTypes(sv); foreach (var kvp in types) { if (!asmTypes.ContainsKey(kvp.Key)) { asmTypes.Add(kvp.Key, kvp.Value); } else { List <string> cTypes = asmTypes[kvp.Key]; // Check if each type in kvp.Value is not in cTypes foreach (string s in kvp.Value) { if (!cTypes.Contains(s)) { cTypes.Add(s); } } } } } else { Dictionary <string, List <string> > asmType = GetType(sv); var iter = asmType.GetEnumerator(); iter.MoveNext(); KeyValuePair <string, List <string> > kvp = iter.Current; if (!asmTypes.ContainsKey(kvp.Key)) { asmTypes.Add(kvp.Key, kvp.Value); } else { List <string> cTypes = asmTypes[kvp.Key]; cTypes.AddRange(kvp.Value); } } } //return types; return(asmTypes); }
public void ReverseRotate_Test() { var dsArray = new DSArray <int>(10); dsArray._data = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; dsArray.ReverseRotate(2); Assert.IsTrue(dsArray._data[dsArray.Count - 1] == 2); Assert.IsTrue(dsArray._data[0] == 3); }
/// <summary> /// Whether sv is double or arrays contains double value. /// </summary> /// <param name="sv"></param> /// <param name="core"></param> /// <returns></returns> public static bool ContainsDoubleElement(StackValue sv, RuntimeCore runtimeCore) { Executable exe = runtimeCore.DSExecutable; if (!sv.IsArray) { return(exe.TypeSystem.GetType(sv) == (int)PrimitiveType.Double); } DSArray array = runtimeCore.Heap.ToHeapObject <DSArray>(sv); return(array.Values.Any( v => (v.IsArray && ContainsDoubleElement(v, runtimeCore)) || (exe.TypeSystem.GetType(v) == (int)PrimitiveType.Double))); }
public void FindFrequency_Of_All_Element() { var dsArray = new DSArray <int>(10); dsArray._data = new int[] { 1, 2, 2, 2, 2, 6, 7, 8, 8, 1 }; var returnValue = dsArray.FindFrequencyOfElement(); Assert.AreEqual(2, returnValue[1]); Assert.AreEqual(4, returnValue[2]); Assert.AreEqual(1, returnValue[6]); Assert.AreEqual(1, returnValue[7]); Assert.AreEqual(2, returnValue[8]); Assert.IsFalse(returnValue.ContainsKey(9)); }