static void Main(string[] args) { int[] sortedArray = new int[] { 1, 2, 3, 4, 5 }; int[] unsortedArray = new int[] { 14, 7, 3, 12, 9, 11, 6, 2 }; //SequentialSearch Console.WriteLine("Sequential Search"); Console.WriteLine(Sequential.Search(sortedArray, 5)); //BinarySearch (Only works on sorted arrays) Console.WriteLine(); Console.WriteLine("Binary Search"); Console.WriteLine(Binary.Search(sortedArray, 5)); //InsertionSort Console.WriteLine(); Console.WriteLine("Insertion Sort"); Insertion.Sort(unsortedArray); foreach (var item in unsortedArray) { System.Console.WriteLine(item); } //BubbleSort unsortedArray = new int[] { 14, 7, 3, 12, 9, 11, 6, 2 }; Console.WriteLine(); Console.WriteLine("BubbleSort"); Bubble.Sort(unsortedArray); foreach (var item in unsortedArray) { System.Console.WriteLine(item); } //MergeSort unsortedArray = new int[] { 14, 7, 3, 12, 9, 11, 6, 2 }; Console.WriteLine(); Console.WriteLine("MergeSort"); Merge.Sort(unsortedArray, 0, unsortedArray.Length - 1); foreach (var item in unsortedArray) { System.Console.WriteLine(item); } //LinkedList-Search LinkedList <int> sortedLlist = new LinkedList <int>(sortedArray); System.Console.WriteLine(); System.Console.WriteLine("LinkedList Search"); Console.WriteLine(Llist.Search(sortedLlist, 5)); //LinkedList-Insert System.Console.WriteLine(); System.Console.WriteLine("LinkedList Insert"); Llist.Insert(sortedLlist, 10); foreach (var item in sortedLlist) { System.Console.WriteLine(item); } }
public void Lab2() { var bubble = new Bubble(); Lab2.Student[][] students = { // PI-301z new[] { new Lab2.Student { AverageMark = 54, FirstName = "A", LastName = "AA", Group = "PI-301z" }, new Lab2.Student { AverageMark = 32, FirstName = "B", LastName = "BB", Group = "PI-301z" }, new Lab2.Student { AverageMark = 83, FirstName = "C", LastName = "CC", Group = "PI-301z" }, }, // PI-302z new[] { new Lab2.Student { AverageMark = 53, FirstName = "S", LastName = "SS", Group = "PI-301y" }, new Lab2.Student { AverageMark = 31, FirstName = "T", LastName = "TT", Group = "PI-301y" }, new Lab2.Student { AverageMark = 85, FirstName = "U", LastName = "UU", Group = "PI-301y" }, }, }; var studentComparer = new Lab2StudentComparer(); Print("Before", students[0]); var result = bubble.Sort(students[0], studentComparer); Print("After", result); var allStudents = new List <Lab2.Student>(); foreach (var group in students) { foreach (var student in group) { allStudents.Add(student); } } Print("Before bubble sort", allStudents); result = bubble.Sort(allStudents.ToArray(), studentComparer); Print("After bubble sort", result); Print("Before heap sort", students[0]); var heap = new Heap <Lab2.Student>(students[0], studentComparer); heap.Sort(); Print("After heap sort", heap.Array.ToArray()); }
public void Lab3() { Student[] students = { new Student { AverageMark = 45, CanPlay = false, Firstname = "A", Surname = "AA" }, new Student { AverageMark = 93, CanPlay = true, Firstname = "B", Surname = "BB" }, new Student { AverageMark = 23, CanPlay = false, Firstname = "C", Surname = "CC" }, new Student { AverageMark = 15, CanPlay = true, Firstname = "D", Surname = "DD" }, new Student { AverageMark = 19, CanPlay = false, Firstname = "E", Surname = "EE" }, new Student { AverageMark = 88, CanPlay = true, Firstname = "F", Surname = "FF" }, new Student { AverageMark = 34, CanPlay = false, Firstname = "G", Surname = "GG" }, new Student { AverageMark = 79, CanPlay = true, Firstname = "H", Surname = "HH" }, new Student { AverageMark = 90, CanPlay = false, Firstname = "I", Surname = "II" }, new Student { AverageMark = 57, CanPlay = true, Firstname = "J", Surname = "JJ" }, }; var bubble = new Bubble(); students = bubble.Sort(students, new Lab3StudentComparer()); Console.WriteLine("Students before remove."); foreach (var student in students) { Console.WriteLine(student.ToString()); } Console.WriteLine(""); int index = Interpolation.Search(students, s => s.AverageMark, 57); if (index == -1) { Console.WriteLine("Nothing found." + Environment.NewLine); } else { Console.WriteLine($"Found student: {students[index]}, index {index}{Environment.NewLine}"); List <Student> tmp = new List <Student>(students); tmp.RemoveAt(index); students = tmp.ToArray(); Console.WriteLine("Students after remove."); foreach (var student in students) { Console.WriteLine(student.ToString()); } } }